How To Find An Array Of Strings In A String?
I'd like to search a string for multiple strings, and return true if it finds any of them in there, false otherwise, something like this: var s = 'thing1 thing2' s.contains(['thing
Solution 1:
You can use Array.some
and String.indexOf
or String.includes
var s1 = "thing1 thing2";
var s2 = "Hello Kitty";
var r1 = ["thing1","thing44444"].some( x => s1.includes(x));
var r2 = ["Travis","Heeeeeeter"].some( x => s2.includes(x));
console.log(r1, r2); // true, false
Post a Comment for "How To Find An Array Of Strings In A String?"