A did a little experiment and found that the following worked fine. The only overhead is the generation of the regexps for each element of the array. If check is zero or above, one of the strings was found.
if (!('included' in Array.prototype)) {
Array.prototype.included = function() {
return arr.map(function (item) {
var regex = new RegExp(item, 'g');
if (regex.test(str)) return true;
return false;
}).indexOf(true);
};
}
To return a boolean instead of a number just change it to:
if (!('included' in Array.prototype)) {
Array.prototype.included = function () {
var regex, found = false;
for (var i = 0, l = this.length; i < l; i++) {
regex = new RegExp(this[i], 'g');
if (regex.test(str)) { found = true; break; }
}
return found;
};
}
var found = arr.included(str);
This is an edit of my previous answer because I realised I hadn't actually answered the question :)
RegExp(strings.join('|')).test(myString)