The JavaScript Array.isArray() method
The Array.isArray() method returns true if a value is an array, and false for anything else. Array.isArray([1, 2]) is true; Array.isArray("abc") is false. It's the reliable array check, because typeof an array returns "object", not "array".
Overview
Array.isArray() exists because there's no clean way to detect an array otherwise. typeof reports "object" for arrays (and for null, dates and plain objects), so it can't tell an array apart. Array.isArray(value) answers the question directly with a boolean.
You reach for it whenever a value could be "one thing or a list of things" — a function that accepts either a single item or an array, JSON you didn't generate, an API response of an uncertain shape. if (Array.isArray(input)) { ... } else { ... } lets you branch safely.
It's a static method on the Array constructor, so you call it as Array.isArray(x), never on an instance. It even works correctly across iframes and realms, where instanceof Array can give the wrong answer (each frame has its own Array). That cross-realm reliability is why it's the recommended check over instanceof.
Syntax
Array.isArray(value)
Array.isArray([1, 2, 3]) // true
Array.isArray("abc") // false
Array.isArray({ a: 1 }) // false
Array.isArray(null) // false
Parameters
The Array.isArray() method accepts the following parameters.
| Parameter | Description |
|---|---|
value |
The value to test. Returns true only if it is an array. |
Example
<pre id="out" style="font:15px ui-monospace,monospace"></pre>
<script>
const values = [[1, 2], 'text', { a: 1 }, null];
const lines = values.map(v =>
JSON.stringify(v) + ' -> ' + Array.isArray(v)
);
document.getElementById('out').textContent = lines.join('\n');
</script>
Best practices
- Use
Array.isArray(x)to detect arrays — never typeof, which returns"object". - Prefer it over instanceof Array, which can fail across iframes.
- Use it to handle functions that accept either a single value or an array.
- Call it on the constructor (
Array.isArray), not on an instance.
Frequently asked questions
How do I check if something is an array in JavaScript?
Array.isArray(value), which returns true for arrays and false otherwise.Why can't I use typeof to detect an array?
"object", the same as for plain objects and null. It can't distinguish arrays.What is the difference between Array.isArray() and instanceof Array?
Array.isArray() also works across iframes/realms, where instanceof can give a false negative. Array.isArray() is more reliable.Does Array.isArray() return true for array-like objects?
arguments object is array-like but not an array, so it returns false. Convert it with Array.from() first.