Q:

how to check if array

Array.isArray([1, 2, 3]);	// true
Array.isArray('asdf');		// false
1

 function myFunction() {
  var fruits = ["Banana", "Orange", "Apple", "Mango"];
  var x = document.getElementById("demo");
  x.innerHTML = Array.isArray(fruits);
} 
1
// Check if something is an Array 
// just like you do with "typeof"
Array.isArray([1, 2, 3]);	// true
Array.isArray('asdf');		// false
0

New to Communities?

Join the community