The Wayback Machine - https://web.archive.org/web/20240204105221/https://www.geeksforgeeks.org/javascript-array-isarray-method/
Open In App
Related Articles

JavaScript Array isArray() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

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




// JavaScript code for isArray() function
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




// JavaScript code for isArray() function
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




// JavaScript code for isArray() function
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




// JavaScript code for isArray() function
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:

  • 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
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials