JavaScriptArraysBeginner

Array.isArray()

Checks if a value is an array (true/false).

Review the syntaxStudy the examplesOpen the coding app
Array.isArray(value)

This static page keeps the syntax and examples indexed for search, while the coding app handles interactive exploration and saved references.

What it does

Overview

Checks if a value is an array (true/false).

Array.isArray() is the standard and most reliable method for determining whether a value is an Array. While the 'typeof' operator returns 'object' for arrays, Array.isArray() correctly identifies them. Critically, it is 'realm-aware', meaning it works across different execution contexts (like iframes or window objects) where 'instanceof Array' would fail because the Array constructor differs between frames. Performance is highly optimized (O(1)) as it checks the internal [[Class]] property. It returns false for TypedArrays, the 'arguments' object, and objects that have Array.prototype in their prototype chain via Object.create() but are not true array instances.

Quick reference

Syntax

Array.isArray(value)

Inputs

Parameters

valueany · The value to test.

See it in practice

Examples

1

Basic Type Validation

console.log(Array.isArray([1, 2, 3]));
console.log(Array.isArray({ key: 'value' }));
console.log(Array.isArray('Hello World'));
console.log(Array.isArray(new Array(5)));
Output:
true false false true

Demonstrates how the method distinguishes between actual array literals/constructors and other common types like objects and strings.

2

Handling Array-like Objects

const checkArguments = function() {
  return Array.isArray(arguments);
};

const nodeList = document.querySelectorAll('div');

console.log(checkArguments(1, 2));
console.log(Array.isArray(nodeList));
console.log(Array.isArray(Array.from(nodeList)));
Output:
false false true

Array-like objects such as 'arguments' and 'NodeList' return false. To treat them as arrays, they must first be converted using Array.from().

3

Edge Case: Array Prototype Inheritance

const fakeArray = Object.create(Array.prototype);

console.log(fakeArray instanceof Array);
console.log(Array.isArray(fakeArray));
Output:
true false

This shows the precision of isArray(). An object created with Array.prototype will pass an 'instanceof' check but is correctly identified as not being a true array by isArray().

Debug faster

Common Errors

1

LogicError

Cause: Using 'typeof' to check for arrays, which returns 'object' for both arrays and standard objects.

Fix: Replace 'typeof' checks with Array.isArray() when logic depends on array-specific methods.

const data = [1, 2]; if (typeof data === 'object') { /* This runs for {} too! */ }
2

LogicError

Cause: Assuming TypedArrays (like Int8Array) will return true because they share array-like behaviors and naming.

Fix: Check for TypedArrays specifically or ensure data is converted to a standard array if isArray() is the gatekeeper.

const buffer = new Uint8Array(8); console.log(Array.isArray(buffer)); // returns false

Runtime support

Compatibility

Node.js, BrowserAll modern browsers, IE9+ES5.1 (2011)

Source: MDN Web Docs

Common questions

Frequently Asked Questions

Checks if a value is an array (true/false).

value: The value to test.

LogicError: Replace 'typeof' checks with Array.isArray() when logic depends on array-specific methods. LogicError: Check for TypedArrays specifically or ensure data is converted to a standard array if isArray() is the gatekeeper.