if array does not include javascript code example
Example 1: check if array does not contain value javascript
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var n = fruits.includes("Mango");
var n = fruits.includes("Django");
Example 2: javascript includes
const pets = ['cat', 'dog', 'bat'];
console.log(pets.includes('cat'));
Example 3: check items in array javascript
function checkAllEven(arr) {
return arr.every(function(x){
return x % 2 === 0
})
}
Example 4: javascript includes method
arr.includes(searchElement[, fromIndex = 0])
Example 5: check if array does not contain string js
function checkInput(input, words) {
return words.some(word => input.toLowerCase().includes(word.toLowerCase()));
}
console.log(checkInput('"Definitely," he said in a matter-of-fact tone.',
["matter", "definitely"]));
Example 6: check if array does not contain string js
function checkInput(input, words) {
return words.some(word => new RegExp(word, "i").test(input));
}
console.log(checkInput('"Definitely," he said in a matter-of-fact tone.',
["matter", "definitely"]));