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.
Demo
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
| Name | Type | Required | Description |
|---|---|---|---|
| value | any | yes | Any 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
const list = Array.isArray(input) ? input : [input];
if (!Array.isArray(data)) throw new Error("expected an array");
function walk(node) { if (Array.isArray(node)) node.forEach(walk); }
Examples
Pitfalls
typeof [] === typeof {}
Array.isArray([])
iframeArray instanceof Array
Array.isArray(iframeArray)
Array.isArray(document.querySelectorAll("li"))
Array.isArray(Array.from(nodeList))
When to use
- 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
- You want to accept array-likes too → check for a numeric length instead
- You want typed arrays too → ArrayBuffer.isView, or check both
Notes
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