You can use the Array.isArray() method to check if an object is an array in JavaScript. This method returns true if the object is an array, and false if it is not.

Example:

let arr = [1, 2, 3];
console.log(Array.isArray(arr)); // true
let obj = {name: "John", age: 30};
console.log(Array.isArray(obj)); // false

You can also use instanceof operator to check if an object is an instance of the Array constructor.

let arr = [1, 2, 3];
console.log(arr instanceof Array); // true
let obj = {name: "John", age: 30};
console.log(obj instanceof Array); // false

Another way is to check the constructor property of the object

let arr = [1, 2, 3];
console.log(arr.constructor === Array); // true
let obj = {name: "John", age: 30};
console.log(obj.constructor === Array); // false

Also Read:

Categorized in: