Answers for "Check if an array contains a string in javascript"

6

js check if string includes from array

wordsArray = ['hello', 'to', 'nice', 'day']
yourString = 'Hello. Today is a nice day'.toLowerCase()
result = wordsArray.every(w => yourString.includes(w))
console.log('result:', result)
Posted by: Guest on October-13-2021
0

Check if an array contains a string in javascript

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

console.log(result); // true
Posted by: Guest on April-06-2022
1

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"]));
Posted by: Guest on June-07-2020

Code answers related to "Check if an array contains a string in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language