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

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

<!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 Comment