Array.isArray()
BaselineWidely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
TheArray.isArray()
static method determines whether the passed value is anArray
.
Try it
console.log(Array.isArray([1, 3, 5]));// Expected output: trueconsole.log(Array.isArray("[]"));// Expected output: falseconsole.log(Array.isArray(new Array(5)));// Expected output: trueconsole.log(Array.isArray(new Int16Array([15, 33])));// Expected output: false
Syntax
Array.isArray(value)
Parameters
value
The value to be checked.
Return value
true
ifvalue
is anArray
; otherwise,false
.false
is always returned ifvalue
is aTypedArray
instance.
Description
Array.isArray()
checks if the passed value is anArray
. It performs abranded check, similar to thein
operator, for a private field initialized by theArray()
constructor.
It is a more robust alternative toinstanceof Array
because it avoids false positives and false negatives:
Array.isArray()
rejects values that aren't actualArray
instances, even if they haveArray.prototype
in their prototype chain —instanceof Array
would accept these as it does check the prototype chain.Array.isArray()
acceptsArray
objects constructed in another realm —instanceof Array
returnsfalse
for these because the identity of theArray
constructor is different across realms.
See the article"Determining with absolute accuracy whether or not a JavaScript object is an array" for more details.
Examples
Using Array.isArray()
// all following calls return trueArray.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 falseArray.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 constructorArray.isArray({ __proto__: Array.prototype });
instanceof vs. Array.isArray()
When checking forArray
instance,Array.isArray()
is preferred overinstanceof
because it works across realms.
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 ArrayArray.isArray(arr); // true// The prototype of arr is xArray.prototype, which is a// different object from Array.prototypearr instanceof Array; // false
Specifications
Specification |
---|
ECMAScript® 2026 Language Specification # sec-array.isarray |