Javascript Tutorial to Check if Object is an Array Using isArray() Method

 

 

The isArray() method determines whether an object is an array.

This function returns true if the object is an array, and false if not.

 

 

<!DOCTYPE html>
<html>
<body>

<p>Click the button to check if "fruits" is an array.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
  var fruits = ["Banana", "Orange", "Apple", "Mango"];
  var x = document.getElementById("demo");
  x.innerHTML = Array.isArray(fruits);
}
</script>

</body>
</html>

Leave a Reply