Array.isArray()

Exists because typeof is useless here — it reports "object" for arrays, null, dates and plain objects alike. This is the check that actually answers the question.

Array static methodES5 (2009)Live demo
Common call
Array.isArray(value)
Returns
boolean — true only for genuine arrays
Replaces
typeof checks, and instanceof Array
Watch out
a typed array is NOT an array; nor is anything merely array-like
Array.isArray(valuevalue — Any value. Only a genuine Array — including one from another frame or realm — returns true.type: any · required)
→ boolean

Demo

Live evaluation
Try:
Inputs
jsonstringa JSON value, e.g. [1,2] or {"length":2}
Output
Array.isArray(JSON.parse('[1,2]'))
true

The demo parses a JSON literal so you can try real shapes. Only the genuine array answers true. The array-LIKE object — a plain object with a length property — is false, which is the case that matters most, since such objects behave like arrays in some code and break in the rest. null is false rather than throwing, unlike a property access would be. JSON cannot express a typed array, but those are false too: Int8Array and friends are a separate family, not Arrays.

Parameters

NameTypeRequiredDescription
valueanyyesAny value. Only a genuine Array — including one from another frame or realm — returns true.

Return value

boolean — True only for real arrays. False for array-like objects, typed arrays, strings and everything else. Works across realms, unlike instanceof.

Common patterns

Guard a polymorphic argument
Accept one item or many.
const list = Array.isArray(input) ? input : [input];
Validate parsed JSON
JSON.parse can return any shape.
if (!Array.isArray(data)) throw new Error("expected an array");
Recurse into nested structures
The standard test when walking a tree.
function walk(node) {
  if (Array.isArray(node)) node.forEach(walk);
}

Examples

1. A real array
Array.isArray([1, 2])
Returns
true
2. typeof is useless
typeof []
Returns
'object'
3. Array-like is false
Array.isArray({length: 1})
Returns
false
4. Typed array is false
Array.isArray(new Int8Array(2))
Returns
false
5. null is false
Array.isArray(null)
Returns
false
6. instanceof mostly works
[] instanceof Array
Returns
true // but not across realms

Pitfalls

1. typeof cannot do this job
typeof returns "object" for arrays, plain objects, dates and null alike. It is the wrong tool entirely, which is exactly why this static exists.
Indistinguishable
typeof [] === typeof {}
true
Use isArray
Array.isArray([])
true
2. instanceof breaks across realms
An array from an iframe, a worker or a Node vm has a DIFFERENT Array constructor, so instanceof Array is false even though it is a genuine array. Array.isArray is specified to work regardless of realm.
Cross-realm fails
iframeArray instanceof Array
false
isArray works
Array.isArray(iframeArray)
true
3. Array-like is not an array
A NodeList, the arguments object, or any object with a length are all false. That is correct — they lack the array methods — but it surprises people whose code has been indexing them happily.
Not an array
Array.isArray(document.querySelectorAll("li"))
false
Convert first
Array.isArray(Array.from(nodeList))
true

When to use

Use it
  • Any check of whether a value is genuinely an array
  • Validating parsed JSON or untrusted input
  • Walking nested structures where arrays need different handling
  • Anywhere instanceof Array might cross a realm boundary
Reach for something else
  • You want to accept array-likes too → check for a numeric length instead
  • You want typed arrays too → ArrayBuffer.isView, or check both

Notes

Complexity
O(1) — an internal slot check, not a prototype walk
Return
A boolean; nothing is modified
CPython impl
V8: Builtins-array-isarray.tq
Memory
No allocation
Thread-safe
Single-threaded; the value is only inspected

FAQ

It works within one realm but fails across them. An array created in an iframe, a web worker or a Node vm context has a different Array constructor, so instanceof returns false for a perfectly real array. Array.isArray checks an internal slot and is realm-independent.

Array.isArray(fromIframe);   // true
fromIframe instanceof Array;  // false

History

ES5
Array.isArray added in 2009, replacing the Object.prototype.toString.call(x) === "[object Array]" idiom.