xxxxxxxxxx
<!DOCTYPE html>
<html>
<body>
<p>Click the button to check if "fruits" is an array.</p>
<button onclick="checkArrayValueOrNot()" id="btnClick">Click </button>
<p id="demo"></p>
<script>
function checkArrayValueOrNot() {
var states =["Maharashtra","Tamil Nadu","Uttar Pradesh","West Bengal","Delhi"];
var x = document.getElementById("demo");
x.innerHTML = Array.isArray(states);
}
</script>
</body>
xxxxxxxxxx
var arrayList = [1 , 2, 3];
console.log(Array.isArray(arrayList)) // true
// method 1
if(Array.isArray(arrayList)){
console.log("is array")
}
// method 2
if(Object.prototype.toString.call(arrayList) === '[object Array]') {
console.log('Array!');
}