javascript test if array code example
Example 1: javascript check if is array
var colors=["red","green","blue"];
if(Array.isArray(colors)){
}
Example 2: javascript test if it is an array
if (Array.isArray(object)) {
} else {
}
Array.isArray([1, 2, 3, 4]);
Array.isArray(4);
Example 3: js test if array
if(Array.isArray(myVarToTest)) {
} else {
}
Example 4: how to recognize an array in javascript
const array = [1, 2, 3];
Array.isArray(array);
Array.isArray(object);
Array.isArray(string);
Array.isArray(empty);
({}).toString.call(array);
({}).toString.call(object);
({}).toString.call(string);
({}).toString.call(empty);
Example 5: javascript check if array is in array
var array = [1, 3],
prizes = [[1, 3], [1, 4]],
includes = prizes.some(a => array.every((v, i) => v === a[i]));
console.log(includes);
Example 6: check items in array javascript
function checkAllEven(arr) {
return arr.every(function(x){
return x % 2 === 0
})
}