The Array.isArray()
method checks whether the passed value is an Array.
Array.isArray(value)
let a = Array.isArray([1, 2, 3]); console.log(a);// true a = Array.isArray({foo: 123}); //from w ww . j av a 2 s . c o m console.log(a);// false a = Array.isArray('foobar'); console.log(a);// false a = Array.isArray(undefined); console.log(a);// false // all following calls return true console.log(Array.isArray([])); console.log(Array.isArray([1])); console.log(Array.isArray(new Array())); console.log(Array.isArray(new Array('a', 'b', 'c', 'd'))); console.log(Array.isArray(new Array(3))); console.log(Array.isArray(Array.prototype)); // all following calls return false console.log(Array.isArray()); console.log(Array.isArray({})); console.log(Array.isArray(null)); console.log(Array.isArray(undefined)); console.log(Array.isArray(42)); console.log(Array.isArray('Array')); console.log(Array.isArray(true)); console.log(Array.isArray(false)); console.log(Array.isArray(new Uint8Array(32)));