Array.isArray([]) //true
Array.isArray({}) //false
Array.isArray('') //false
Array.isArray(null) //false
const names = ["code","codepadding"]
const key = "codepadding";
var have = names.includes(key) // return true / false
if(have){
// do something
}
if(Array.isArray(myVarToTest)) {
// myVatToTest is an array
} else {
// myVarToTest is not an array
}
function isArray(value) {
return Object.prototype.toString.call(value) === "[object Array]";
}
const arr = ["name"]
console.log(Array.isArray(arr)); // true
function checkAllEven(arr) {
return arr.every(function(x){
return x % 2 === 0
})
}
//using "every" to check every item in array.
if(Object.prototype.toString.call(someVar) === '[object Array]') {
alert('Array!');
}