Skip to content
Related Articles

Related Articles

JavaScript Array isArray() Method
  • Last Updated : 23 Jun, 2020

Below is the example of the Array isArray() method.

  • Example:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <script>
        // JavaScript code for isArray() function
        function func() {
            document.write(Array.isArray('foobar'));
        }
      
       func();
    </script>

    chevron_right

    
    

  • Output:
    false

The 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 array else it returns false.

Syntax:

Array.isArray(obj)

Parameters: This method accept 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 array otherwise it returns false.



Below example illustrate the Array isArray() method in JavaScript:

  • Example 1: Since the argument passed to the function isArray() is an array therefore this function returns true as the answer.
    Input : print(Array.isArray(['Day','Night','Evening']));
    Output: true
    
  • Example 2: Since the argument passed to the function isArray() is a map therefore this function returns false as the answer.
    Input : print(Array.isArray({foo: 123}));
    Output: false
    
  • Example 3: Since the argument passed to the function isArray() is a string therefore this function returns false as the answer.
    Input : print(Array.isArray('foobar'));
    Output: false
    

Code for the above method is provided below:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
    // JavaScript code for isArray() function
    function func() {
        document.write(Array.isArray(['Day','Night','Evening']));
    }
    func();
</script>

chevron_right


Output:

true

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
    // JavaScript code for isArray() function
    function func() {
        document.write(Array.isArray({foo: 123}));
    }
    func();
</script>

chevron_right


Output:

false

Supported Browsers: The browsers supported by JavaScript Array isArray() method are listed below:

  • Google Chrome 5.0
  • Microsoft Edge 9.0
  • Mozilla Firefox 4.0
  • Safari 5.0
  • Opera 10.5

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :