how to chack string exeist in array or not js code example
Example 1: 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');
checkAvailability(fruits, 'banana');
Example 2: how to Check if an array contains a string
const colors = ['red', 'green', 'blue'];
const result = colors.includes('red');
console.log(result);
const colors = ['Red', 'GREEN', 'Blue'];
const result = colors.map(e => e.toLocaleLowerCase())
.includes('green');
console.log(result);