JavaScript Program to Check if An Object is An Array

To understand this example, you should have the knowledge of the following JavaScript programming topics:


Example: Check Array Using Array.isArray()

Output

[1,2,3] is an array.

In the above program, the Array.isArray() method is used to check if an object is an array.

The Array.isArray() method returns true if an object is an array, otherwise returns false.

Note: For an array, the typeof operator returns an object.

For example,

const arr = [1, 2, 3];
console.log(typeof arr); // object