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:
- 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.
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();
|
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();
|
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();
|
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();
|
We have a complete list of Javascript Array methods, to check those please go through this Javascript Array Complete reference article.
Supported Browsers:
- 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!
Looking for a place to share your ideas, learn, and connect? Our Community portal is just the spot! Come join us and see what all the buzz is about!
Last Updated :
27 Dec, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...