1var colors = ["red", "blue", "green"];
2var hasRed = colors.includes("red"); //true
3var hasYellow = colors.includes("yellow"); //false
1 var fruits = ["Apple", "Banana", "Mango", "Orange", "Papaya"];
2
3 // Check if a value exists in the fruits array
4 if(fruits.indexOf("Mango") !== -1){
5 alert("Value exists!")
6 } else{
7 alert("Value does not exists!")
8 }
1const pets = ['cat', 'dog', 'bat'];
2
3console.log(pets.includes('cat'));
4// output: true
1const array1 = [1, 2, 3];
2
3console.log(array1.includes(2));
4// expected output: true
5
6const pets = ['cat', 'dog', 'bat'];
7
8console.log(pets.includes('cat'));
9// expected output: true
10
11console.log(pets.includes('at'));
12// expected output: false
1[1, 2, 3].includes(2); // true
2[1, 2, 3].includes(4); // false
3[1, 2, 3].includes(1, 2); // false (second parameter is the index position in this array at which to begin searching)
1let storyWords = ['extremely', 'literally', 'actually', 'hi', 'bye', 'okay']
2let unnecessaryWords = ['extremely', 'literally', 'actually' ];
3
4let betterWords = storyWords.filter(function(word) {
5 return !unnecessaryWords.includes(word);
6});
7console.log(betterWords) // ['hi' 'bye' 'okay]