The Javascript arr.isArray() method determines whether the value passed to this function is an array or not. This function returns true if the argument passed is an array else it returns false.
Syntax:
Array.isArray(obj)
Parameters: This method accepts a single parameter as mentioned above and described below:
- obj: This parameter holds the object that will be tested.
Return value: This function returns the Boolean value true if the argument passed is an array otherwise it returns false.
Below is an example of the Array isArray() method.
Example 1: In this example, we will pass a string value to the isArray() and check what value is returned.
JavaScript
function func() {
console.log(Array.isArray( 'foobar' ));
}
func();
|
Output:
false
Example 2: Since the argument passed to the function isArray() is an array therefore this function returns true as the answer.
JavaScript
function func() {
console.log(Array.isArray([ 'Day' , 'Night' , 'Evening' ]));
}
func();
|
Output:
true
Example 3: Since the argument passed to the function isArray() is a map therefore this function returns false as the answer.
JavaScript
function func() {
console.log(Array.isArray({ foo: 123 }));
}
func();
|
Output:
false
Example 4: Since the argument passed to the function isArray() is a string, therefore, this function returns false as the answer.
Javascript
function func() {
console.log(Array.isArray({ foo: 123 }));
}
func();
|
Output:
false
We have a complete list of Javascript Array methods, to check those please go through this Javascript Array Complete reference article.
Supported Browsers: The browsers supported by JavaScript Array isArray() method are listed below:
- Google Chrome 5.0
- Microsoft Edge 12
- Mozilla Firefox 4.0
- Safari 5.0
- Opera 10.5
We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!