JavaScript Check Array isArray

In JavaScript Array is basically an Object, but I want check exactly whether the given variable is Array or not.

When you make use of typeof to identify the Variable type on array, it always return an object, because in JavaScript array is a special type of object.

To solve this Issue, In 2009 new method is introduced, that is Array.isArray(), it takes an array as an argument and returns Boolean(true/false)

in addition to this, we can use instanceof operator, it returns true if an object is created by a given constructor.

Example To check JavaScript Variable is array or not

const arrData = [4,3,1,5,6,7,3,1];


console.log(typeof arrData);  // object

console.log(Array.isArray(arrData));   // true