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

Author: Maciek
More Information: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray
Tags: array

comments powered by Disqus