creation

Array.isArray

Returns true if the value is an Array (works across realms/iframes, unlike `instanceof Array`). Reach for it as the canonical type check before running array-only methods.

Array.isArray(value)

Parameters

Parameter Purpose
value Any value to test
return value boolean — true only for real Array instances (including from other realms)

Examples

console.log(Array.isArray([1, 2, 3]));

Logs: true

console.log(Array.isArray('abc'), Array.isArray({length: 1}));

Logs: false false

console.log(Array.isArray(new Int8Array(3)));

Logs: false (TypedArrays are NOT arrays)

console.log(Array.isArray(Array.from('ab')));

Logs: true

Gotcha

TypedArrays (Int8Array, Uint8Array, etc.) are NOT arrays and return false. Use this instead of `instanceof Array`, which returns false for arrays coming from another iframe/realm.

Related methods

← All JS array methods · TypeScript vs JavaScript