JavaScript Array isArray() | Method

  • by

Using Array isArray() method you can test whether the value passed is an Array or not in JavaScript. This method returns true if an object is an array, otherwise false.

Array.isArray(obj)

The isArray() method, being a static method, is called using the Array class name.

JavaScript Array isArray()

Simple example code ff it finds the passed value is an array, it returns True. Otherwise, it returns False.

<!DOCTYPE html>
<html>
<body>

  <script>
    value1 = "JavaScript";
    console.log(Array.isArray(value1));

    value2 = 18;
    console.log(Array.isArray(value2)); 

    value3 = [];
    console.log(Array.isArray(value3)); 

    value4 = [1, 2, 3, 4];
    console.log(Array.isArray(value4)); 

    value5 = new Array(3);
    console.log(Array.isArray(value5)); 

    value6 = new Uint8Array(16);
    console.log(Array.isArray(value6)); 

  </script>

</body>
</html> 

Output:

JavaScript Array isArray() Method

Do comment if you have any doubts or suggestions on this JS Array method.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Tags:

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.