JavaScript Array isArray() Method
The isArray() method is used to test whether the value passed is an array. If it finds the passed value is an array, it returns True. Otherwise, it returns False.
Syntax
Parameter
obj_value: It is the value of the object which is passed for determining whether it is an array or not.
Return
It returns either false or true, depending on the test.
JavaScript Array isArray() Method Example
Let’s see the below implementations and determine if the value is an array.
Example1
This example shows a basic implementation of isArray() method.
Output:
It is clear that the passed values were not forming any array. Thus, the result is false.
Example2
In this example, we will pass an array and check the resultant.
Output:
Hence, the output says that the passed value is an array.
Example3
Let’s check what if we pass ‘null’ as an object value.
Output:
Example4
Here is the code implementation where the object value is passed as ‘undefined’.
Output:
Example5
Determining the object value and invoking the functions accordingly.
Output:
Function f1() is invoked because the value passed is an array.
Example6
When we pass the object value as ‘True’.
Output:
It shows that value is not in the form of an array.