js check if element in list code example
Example 1: how to check if item is in list js
var myList=["a", "b", "c"];
mylist.includes("d")//returns true or false
Example 2: Checking whether a value exists in an array javascript
const fruits = ['apple', 'banana', 'mango', 'guava'];
function checkAvailability(arr, val) {
return arr.some(arrVal => val === arrVal);
}
checkAvailability(fruits, 'kela'); // false
checkAvailability(fruits, 'banana'); // true