With includes()
, no, but you can achieve the same thing with REGEX via test()
:
var value = /hello|hi|howdy/.test(str);
Or, if the words are coming from a dynamic source:
var words = array('hello', 'hi', 'howdy');
var value = new RegExp(words.join('|')).test(str);
The REGEX approach is a better idea because it allows you to match the words as actual words, not substrings of other words. You just need the word boundary marker \b
, so:
var str = 'hilly';
var value = str.includes('hi'); //true, even though the word 'hi' isn't found
var value = /\bhi\b/.test(str); //false - 'hi' appears but not as its own word