how to check if element is in list javascript code example
Example 1: javascript is int in array
[1, 2, 3].includes(2);
[1, 2, 3].includes(4);
[1, 2, 3].includes(1, 2);
Example 2: how to check if item is in list js
var myList=["a", "b", "c"];
mylist.includes("d")
Example 3: array includes
let storyWords = ['extremely', 'literally', 'actually', 'hi', 'bye', 'okay']
let unnecessaryWords = ['extremely', 'literally', 'actually' ];
let betterWords = storyWords.filter(function(word) {
return !unnecessaryWords.includes(word);
});
console.log(betterWords)
Example 4: check items in array javascript
function checkAllEven(arr) {
return arr.every(function(x){
return x % 2 === 0
})
}