js check array values exist on string code example

Example 1: 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 2: 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"]));

Example 3: how to Check if an array contains a string

// To check if an array contains a string 

const colors = ['red', 'green', 'blue'];
const result = colors.includes('red');

console.log(result); // true

// Or 

const colors = ['Red', 'GREEN', 'Blue'];
const result = colors.map(e => e.toLocaleLowerCase())
                     .includes('green');                          

console.log(result); // true