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



Last Updated : 27 Dec, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads