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>

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

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

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

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


Leave a Reply