Array.isArray(object);
// Prove that Array is also an Object in JavaScript
// Method -1
let arr = [];
console.log(typeof arr);
// Method -2
let arr2 = [];
if (Array.isArray(arr2)) {
console.log(`Array is an Object in JavaScript`);
}
/* The Array.isArray() method indicates whether
the passed value is an array. */
let example1 = [1, 2, 3];
console.log(Array.isArray(example1)); // → true
let example2 = {a: 1, b: 2,c: 3};
console.log(Array.isArray(example2)); // → false
In modern browsers you can do:
Array.isArray(obj)
const data = [1,2,3,4,5];const isArray = Object.prototype.toString.call(data) === '[object Array]';console.log(isArray); // trueconst data = {id: 1, name: “Josh”};const isArray = Object.prototype.toString.call(data) === '[object Array]';console.log(isArray); // false