Check if a value is an array

The simplest way to check if an object is an array (using ECMAScript 5 and higher) is the Array.isArray method.

var x = [1,2,3];
var y = "something else entirely";

console.log(Array.isArray(x)); // returns true
console.log(Array.isArray(y)); // returns false
comments powered by Disqus