1var fruits = ["Banana", "Orange", "Apple", "Mango"];
2
3var n = fruits.includes("Mango"); // true
4
5var n = fruits.includes("Django"); // false
1function checkInput(input, words) {
2 return words.some(word => new RegExp(word, "i").test(input));
3}
4
5console.log(checkInput('"Definitely," he said in a matter-of-fact tone.',
6["matter", "definitely"]));
1const fruits = ['apple', 'banana', 'mango', 'guava'];
2
3function checkAvailability(arr, val) {
4 return arr.some(arrVal => val === arrVal);
5}
6
7checkAvailability(fruits, 'kela'); // false
8checkAvailability(fruits, 'banana'); // true
1private boolean ZitAlInArray(int value, List<Integer> list) {
2 return array.indexOf(value) > -1;
3}
4
5private boolean zitAlInArray(int[] array, int index) {
6 for (int i = 0; i < index; i++) {
7 if (array[i] == array[index]) {
8 return true;
9 }
10 }
11 return false;
12 }
13
1// To check if an array contains a string
2
3const colors = ['red', 'green', 'blue'];
4const result = colors.includes('red');
5
6console.log(result); // true
7
8// Or
9
10const colors = ['Red', 'GREEN', 'Blue'];
11const result = colors.map(e => e.toLocaleLowerCase())
12 .includes('green');
13
14console.log(result); // true