.isArray()
The .isArray()
method returns true
for arrays, otherwise false
.
Note: The .isArray()
method is called on the Array
constructor function and is not a prototype method. That is why .isArray()
is called using Array.isArray()
.
Syntax
Array.isArray(value);
Required parameter value is the value to be checked.
Examples
Check if the following values are arrays:
console.log(Array.isArray([]));// Output: trueconsole.log(Array.isArray({}));// Output: falseconsole.log(Array.isArray(new Array(5)));// Output: trueconsole.log(Array.isArray(true));// Output: false