JavaScript Array isArray() Method

The isArray() method is used to test whether the value passed is an array.

The isArray() method returns true if an object is an array, otherwise false.

The isArray() method, being a static method, is called using the Array class name.

Syntax

Array.isArray(obj)

Parameters: This method accept a single parameter as mentioned above and described below:

obj: Required. It is the value of the object which is passed for determining whether it is an array or not.

Return value

true if the value is an Array; otherwise, false. (A boolean)

Examples

Below are the examples of the Array isArray() method.

Array.isArray([1, 2, 3]);  // true
Array.isArray({foo: 123}); // false
Array.isArray('foobar');   // false
Array.isArray(undefined);  // false
// all following calls return true
Array.isArray([]);
Array.isArray([1]);
Array.isArray(new Array());
Array.isArray(new Array('a', 'b', 'c', 'd'));
Array.isArray(new Array(3));
// Little known fact: Array.prototype itself is an array:
Array.isArray(Array.prototype);

// all following calls return false
Array.isArray();
Array.isArray({});
Array.isArray(null);
Array.isArray(undefined);
Array.isArray(17);
Array.isArray('Array');
Array.isArray(true);
Array.isArray(false);
Array.isArray(new Uint8Array(32));
Array.isArray({ __proto__: Array.prototype });
value1 = "JavaScript";
console.log(Array.isArray(value1)); // false

value2 = 18;
console.log(Array.isArray(value2)); // false

value3 = true;
console.log(Array.isArray(value3)); // false

value4 = [1, 2, 3, 4];
console.log(Array.isArray(value4)); // true

value5 = new Array(3);
console.log(Array.isArray(value5)); // true

value6 = new Uint8Array(16);
console.log(Array.isArray(value6)); // false