The isArray() method checks whether the passed argument is an array or not.
Example
isArray() Syntax
The syntax of the isArray() method is:
Array.isArray(value)
The isArray() method, being a static method, is called using the Array class name.
isArray() Parameters
The isArray() method takes a single parameter:
- value - The value to be checked.
isArray() Return Value
The isArray() method returns:
trueif the passed value isArrayfalseif the passed value is notArray
Note: This method always returns false for TypedArray instances.
Example 1: Using isArray() Method
Output
true false
In the above example, we have used the isArray() method to find out whether fruits and text are arrays or not.
(Array.isArray(fruits)) returns true since fruits is an array object and (Array.isArray(text)) returns false since text is not an array (it's a string).
Example 2: isArray() to Check Other Data Types
Output
true true false false false