How to Check if a Value Is an Array in JavaScript with Array.isArray
Array.isArray(value) gives true when the value is an array and false for anything else, including strings, null and objects that only look like arrays. It's the check to use, because typeof says 'object' for an array.
Syntax
Array.isArray(<value>)
| Part | What it does |
|---|---|
Array.isArray | A static method of Array: you call it on Array itself, not on the value. |
<value> | Any value. The method never throws, whatever you pass. |
It returns true or false. MDN's Array.isArray reference: "The Array.isArray() static method determines whether the passed value is an Array."
The Example
The example checks an array of two colours, an empty array, the string 'red', an object with a 0 key and a length, and null. The last line shows what typeof says about the same array.
Prerequisites
- Node.js. This guide uses Node.js 26.13.1.
Step 1: Write the Code
Create a file named main.js:

console.log(Array.isArray(['red', 'green']));
console.log(Array.isArray([]));
console.log(Array.isArray('red'));
console.log(Array.isArray({ 0: 'red', length: 1 }));
console.log(Array.isArray(null));
console.log(typeof ['red', 'green']);
Step 2: Run It
node main.js
true
true
false
false
false
object

The command is the same in zsh, bash and PowerShell.
What Happened
- Both arrays gave
true, the empty one included. - The string
'red'gavefalse. A string has a length and indexes, but it isn't an array. - The object
{ 0: 'red', length: 1 }gavefalse. It looks like an array from the outside, but it wasn't made as one. nullgavefalsewithout an error, so you don't need a null check first.typeofgaveobjectfor the array, which is why it can't tell an array from any other object.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Checking with typeof value === 'object' | Objects and null pass as well | Use Array.isArray(value) |
Calling it on the value: value.isArray() | TypeError, because arrays have no isArray method | Call it on Array: Array.isArray(value) |
Treating a typed array, such as Uint8Array, as an array | Array.isArray gives false for it | Check for the typed array's own class with instanceof |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
TypeError: roles.join is not a function | The value is a string or an object, not an array | Check Array.isArray(roles) before using array methods |
| An array check passes for a string in another check you wrote | The check used length or indexes | Use Array.isArray |
FAQ
What's the difference between Array.isArray and instanceof Array?
For arrays made in your own code, both give true. MDN says Array.isArray() "is preferred over instanceof because it works across realms": an array made in another realm, such as another frame in a browser, gives false with instanceof Array.
Is an array made with new Array(3) an array?
Yes. Array.isArray(new Array(3)) is true, even though its three slots are empty.
Conclusion
Array.isArray is the reliable way to know you have an array before you call array methods on it. It returns false for everything else, null included, and it never throws.
Additional Resources
- Array.isArray(), on MDN.
