JavaScript isArray() | Check if an Object is an Array or Not

The JavaScript isArray() method is used to check whether a specified object is an array or not. For example:

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>

   <p id="xyz"></p>

   <script>
      const countries = ["Luxembourg", "USA", "Australia", "UK", "USA", "Canada"];
      let x = Array.isArray(countries);
      
      if(x)
         document.getElementById("xyz").innerHTML = "'countries' is an Array.";
      else
         document.getElementById("xyz").innerHTML = "'countries' is not an Array.";
   </script>
   
</body>
</html>
Output

JavaScript isArray() Syntax

The syntax of isArray() method in JavaScript is:

Array.isArray(object)

Note - The Array before isArray() is necessary, because of the static property.

The isArray() method returns true if specified object is an array, otherwise returns false. For example:

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>

   <p id="abc"></p>

   <script>
      let myVar = "jobails.com";
      document.getElementById("abc").innerHTML = Array.isArray(myVar);
   </script>
   
</body>
</html>
Output

JavaScript Online Test


« Previous Tutorial Next Tutorial »