Array.isArray() is the correct way to ask “is this a real array?” It returns true or false, works across iframes, and rejects array-like objects. This tutorial covers syntax, five examples, pitfalls of typeof, and comparisons with instanceof.
01
Syntax
Array.isArray(x)
02
Static
On Array
03
Boolean
true / false
04
Not typeof
object trap
05
Not array-like
Real arrays only
06
ES5
Wide support
Fundamentals
Introduction
JavaScript values come in many shapes. Functions that expect an array need a reliable type check before calling map(), filter(), or other array methods.
Array.isArray() is the built-in answer. Do not rely on typeof (arrays are "object") or loose checks like value.length, which confuse array-like objects with real arrays.
Concept
Understanding the Array.isArray() Method
Array.isArray(value) returns true only when value is a genuine Array instance created in the current realm. It is a static method—you call it on Array, not on an instance.
It checks one level only. A nested array like [1, [2, 3]] is still an array; inner elements are tested separately if needed.
💡
Beginner Tip
Before looping unknown API data, run Array.isArray(data). If false, wrap a single value in [data] or reject the input with a clear error.
Foundation
📝 Syntax
General form of the static method:
JavaScript
Array.isArray(value)
Parameters
value — any JavaScript value to test.
Return value
true if value is an Array.
false for all other types (including null, objects, strings, array-likes).
Common patterns
Array.isArray(items) — guard before array methods.
if (!Array.isArray(x)) throw new TypeError(...) — validation.
Array.isArray(x) ? x : [x] — normalize to array.
data.filter(Array.isArray) — keep only array elements.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Is it an array?
Array.isArray(value)
[] result
true
{} result
false
Array-like object
false (use Array.from)
Prefer over
typeof x === "object"
Compare
📋 Array.isArray() vs typeof vs instanceof Array
Use isArray for the most reliable array type check in everyday code.
isArray
recommended
Cross-realm safe
typeof
"object"
Not specific
instanceof
Array
Iframe issues
length check
unreliable
Array-like trap
Hands-On
Examples Gallery
Open DevTools Console (F12) or use Try-it labs. Example N maps to ?tryit=N.
typeof tells you the broad category. Array.isArray answers the specific question you usually care about.
Example 4 — Guard a Function That Expects an Array
Validate input before calling array methods.
JavaScript
function sumArray(numbers) {
if (!Array.isArray(numbers)) {
throw new TypeError("Input must be an array");
}
return numbers.reduce((sum, n) => sum + n, 0);
}
console.log(sumArray([1, 2, 3]));
// 6