Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Array.isArray

Checks whether a value is an array.

Available since: ES5

Syntax

Array.isArray(value)

Parameters

ParameterTypeDescription
valueanyThe value to check.

Return value

booleantrue if the value is an array.

Examples

An array and a non-array:

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

Output:

true
false

Why typeof does not help:

console.log(typeof []);
console.log(typeof {});

Output:

object
object

Notes

The typeof operator returns object for an array, just like for a plain object. Only Array.isArray() reliably tells them apart.

See also

  • typeof — Returns a string with the type of a value.
  • instanceof — Checks whether an object was created by a class (or a subclass).

Related recipes

In the tutorial

  • Arrays — What an array is in JavaScript: creating one, indexes, length, changing elements and nested arrays.

Thanks for reading!

Donate to the site — we work hard for you.