How can I check if an object is an array?
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
In JavaScript, the correct answer is usually short: use Array.isArray(value). The reason this question keeps coming up is that arrays are objects, typeof returns "object", and some older checks fail when values come from another realm such as an iframe. If you know why those older checks fail, the rule becomes simple and easy to defend.
Use Array.isArray
Array.isArray is the standard, readable, cross-realm-safe way to test for arrays.
This prints true, true, false, false, and false.
The important point is that Array.isArray checks the actual array brand, not whether something merely looks array-like.
Why typeof Does Not Work
A common beginner mistake is to write this:
That prints "object", because arrays are objects in JavaScript. The typeof operator is useful for primitives and functions, but it does not distinguish plain objects from arrays.
So if your goal is "is this value specifically an array," typeof does not answer the question you are asking.
Why instanceof Array Can Be Misleading
This also works in many local cases:
But instanceof depends on the constructor identity in the current realm. If an array was created in another window or iframe, it may not share the same Array constructor object.
That means instanceof Array can return false even though the value is genuinely an array.
In modern code, instanceof is best treated as a narrower local check, not as the primary answer.
Object.prototype.toString as a Fallback
Before Array.isArray was widely available, developers often used Object.prototype.toString.call(value).
This still works, and it handles cross-realm values more reliably than instanceof. But it is more verbose and less direct than Array.isArray, so it is mainly useful for understanding older code or very old JavaScript environments.
Arrays Versus Array-Like Values
Another source of confusion is the difference between arrays and array-like values. A value can have numeric keys and a length property without being an actual array.
Examples include:
- the
argumentsobject in older function patterns - many DOM collections
- custom objects such as
{"0": "a", "1": "b", length: 2}
Array.isArray(arrayLike) is false, which is correct. If you want a real array, convert it explicitly with Array.from rather than pretending it already is one.
Typed Arrays Are Different Too
Typed arrays such as Uint8Array are not normal arrays.
The first line prints false. That is not a bug. Typed arrays are separate built-in types designed for binary data.
If your code should accept both ordinary arrays and typed arrays, write that rule explicitly instead of assuming one check covers both.
Common Pitfalls
The most common mistake is using typeof and expecting arrays to report a unique type name. They do not.
Another mistake is using instanceof Array in code that may receive values from another realm. That often works in tests and then fails in browser integrations.
Developers also sometimes confuse "iterable" or "array-like" with "array." Those are related ideas, but they are not equivalent. Choose the check that matches the contract your function actually requires.
Finally, do not overengineer this. If you are writing modern JavaScript and need to know whether a value is an array, Array.isArray is already the right answer.
Summary
- Use
Array.isArray(value)for normal JavaScript array checks. - Do not use
typeofto distinguish arrays from objects. - '
instanceof Arraycan fail across realms such as iframes.' - '
Object.prototype.toString.call(value)is a valid older fallback.' - Array-like objects and typed arrays are not the same thing as ordinary arrays.
Related reading
- How do I check if a list is empty?
- How do I check if an array includes a value in JavaScript?
- How do I concatenate two lists in Python?
- How do I list all files of a directory?
- How do I make a flat list out of a list of lists?
- How do I sort a dictionary by value?
- How do I split a list into equally-sized chunks?
- How to iterate over a dictionary?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.