JavaScript typeof Array: What It Returns and How to Check Properly

17 August 2026

Learn why typeof returns 'object' for arrays and the best ways to check if a variable is an array in JavaScript, including Array.isArray().

Why typeof Returns "object" for Arrays

In JavaScript, arrays are a special type of object. When you use the typeof operator on an array, it returns the string "object" rather than something like "array". This behaviour often confuses developers, especially those coming from strongly typed languages. The reason is that arrays inherit from Object.prototype and are technically classified as objects under the ECMAScript specification. So, if you write `typeof [1, 2, 3]`, you'll get `"object"`. Understanding this fundamental point is the first step to correctly identifying arrays. You cannot rely on typeof alone, but there are several reliable alternatives you can adopt.

The Standard Way: Array.isArray()

The most straightforward and recommended method to check whether a value is an array is `Array.isArray()`. This static method returns true if the passed value is an array, regardless of the global context. For example, `Array.isArray([1, 2, 3])` returns true, while `Array.isArray({ length: 3 })` returns false. Unlike `instanceof`, `Array.isArray()` works correctly across iframes and different JavaScript realms, making it the gold standard in modern development. Whether you're building a React app or a Node.js backend, using `Array.isArray()` is the cleanest, most predictable approach for array detection in 2026.

Using instanceof Array (and Its Pitfalls)

Another common technique is `value instanceof Array`, which checks if an object appears anywhere in the prototype chain of the constructor. It works in most cases, but it has a significant limitation: it fails with arrays created in a different global context, such as an iframe or a separate Node.js worker. For instance, an array passed from an iframe may not be recognised by the parent page's `instanceof Array`. This can lead to subtle bugs in complex applications. While `instanceof Array` is fine for simple single-realm scripts, you should prefer `Array.isArray()` for robust code, especially when dealing with third-party data or embedded widgets.

Checking Arrays with Object.prototype.toString

A more advanced but extremely reliable technique is to use `Object.prototype.toString.call(value)`. This method returns a string like `"[object Array]"` for arrays and `"[object Object]"` for plain objects. It works across all JavaScript environments, including cross-realm contexts. The syntax is slightly verbose, but it is useful when you need to identify more specific built-in types. Many popular libraries and polyfills use this approach under the hood. If you want a reusable helper, you can define a function like `function isArray(value) { return Object.prototype.toString.call(value) === '[object Array]'; }` for full control, though `Array.isArray()` remains the simpler choice for most cases.

Practical Examples and Common Gotchas

Let's put theory into practice with some typical scenarios. Suppose you're building a UK-facing e-commerce site and you receive product data from an API. You need to ensure the `variants` field is an array before calling `.map()`. Using `Array.isArray(data.variants)` will save your application from crashing. Another gotcha: when checking for arrays in Node.js, remember that `Buffer` instances are also objects, so `typeof` won't distinguish them. Always use a dedicated check. Also, be aware that `arguments` objects are not arrays, even though they look similar. Modern JavaScript provides rest parameters to avoid this confusion, but understanding these pitfalls keeps your code robust and bug-free.

FAQ

No, the typeof operator always returns "object" for arrays. This is a long-standing quirk of JavaScript's design. To correctly identify arrays, you need to use Array.isArray() or a similar technique. Knowing this will save you from writing faulty type-checking logic.

Latest guides