check if list contains string js code example
Example 1: typescript check if element in array
your_array.includes(the_element)
Example 2: how to check if item is in list js
var myList=["a", "b", "c"];
mylist.includes("d")
Example 3: javascript list include
const array1 = [1, 2, 3];
console.log(array1.includes(2));
const pets = ['cat', 'dog', 'bat'];
console.log(pets.includes('cat'));
console.log(pets.includes('at'));
Example 4: check if array does not contain string js
function checkInput(input, words) {
return words.some(word => input.toLowerCase().includes(word.toLowerCase()));
}
console.log(checkInput('"Definitely," he said in a matter-of-fact tone.',
["matter", "definitely"]));
Example 5: check if array does not contain string js
function checkInput(input, words) {
return words.some(word => new RegExp(word, "i").test(input));
}
console.log(checkInput('"Definitely," he said in a matter-of-fact tone.',
["matter", "definitely"]));