HTML: Markup language
CSS: Styling language
JavaScript: Scripting language
Web APIs: Programming interfaces
All web technology
Learn web development
Discover our tools
Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The Array.isArray() static method determines whether the passed value is an Array.
Array.isArray()
Array
console.log(Array.isArray([1, 3, 5])); // Expected output: true console.log(Array.isArray("[]")); // Expected output: false console.log(Array.isArray(new Array(5))); // Expected output: true console.log(Array.isArray(new Int16Array([15, 33]))); // Expected output: false
Array.isArray(value)
value
The value to be checked.
true if value is an Array; otherwise, false. false is always returned if value is a TypedArray instance.
true
false
TypedArray
Array.isArray() checks if the passed value is an Array. It performs a branded check, similar to the in operator, for a private field initialized by the Array() constructor.
in
Array()
It is a more robust alternative to instanceof Array because it avoids false positives and false negatives:
instanceof Array
Array.prototype
See the article "Determining with absolute accuracy whether or not a JavaScript object is an array" for more details.
// all following calls return true Array.isArray([]); Array.isArray([1]); Array.isArray(new Array()); Array.isArray(new Array("a", "b", "c", "d")); Array.isArray(new Array(3)); // Little known fact: Array.prototype itself is an array: Array.isArray(Array.prototype); // all following calls return false Array.isArray(); Array.isArray({}); Array.isArray(null); Array.isArray(undefined); Array.isArray(17); Array.isArray("Array"); Array.isArray(true); Array.isArray(false); Array.isArray(new Uint8Array(32)); // This is not an array, because it was not created using the // array literal syntax or the Array constructor Array.isArray({ __proto__: Array.prototype });
When checking for Array instance, Array.isArray() is preferred over instanceof because it works across realms.
instanceof
const iframe = document.createElement("iframe"); document.body.appendChild(iframe); const xArray = window.frames[window.frames.length - 1].Array; const arr = new xArray(1, 2, 3); // [1, 2, 3] // Correctly checking for Array Array.isArray(arr); // true // The prototype of arr is xArray.prototype, which is a // different object from Array.prototype arr instanceof Array; // false
Enable JavaScript to view this browser compatibility table.
Array.isArray
core-js