javascript inarray check code example
Example 1: javascript element in array
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var n = fruits.includes("Mango");
Example 2: js test if array
if(Array.isArray(myVarToTest)) {
} else {
}
Example 3: js check if array
Array.isArray([1, 2, 3]);
Array.isArray('asdf');
Example 4: javascript is int in array
[1, 2, 3].includes(2);
[1, 2, 3].includes(4);
[1, 2, 3].includes(1, 2);
Example 5: check items in array javascript
function checkAllEven(arr) {
return arr.every(function(x){
return x % 2 === 0
})
}