JSFiddle - React, Tailwind, and code Playground
by 3rror404
JavaScript
var substrings = ["on", "two", "three"];
var str;
// Setup
console.log("Substrings: " + substrings.join(","));
// Try it where we expect a match
str = "this has one".split(' ');
if (substrings.some((v) => {
return str.some((w) => {
return w.indexOf(v) >= 0;
})
})) {
console.log("Match using '" + str + "'");
} else {
console.log("No match using '" + str + "'");
}
// Try it where we DON'T expect a match
str = "this doesn't have any";
if (substrings.some(function(v) { return str.indexOf(v) >= 0; })) {
console.log("Match using '" + str + "'");
} else {
console.log("No match using '" + str + "'");
}