JavaScript

How to check if an object is an array in JavaScript

In this tutorial, we are going to see how to check if an object is an array using the Array.isArray() method which returns a boolean determining whether the current value is an array or not. It will return true if it is an array, otherwise false.
 

How to check if an object is an array in JavaScript
var arr = ['a', 'b', 'c', 'd'];

Array.isArray(arr);  //true

Array.isArray({key: 'value'});  ///false

Array.isArray('string');  //false
[st_adsense] mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *