function isSubstring(w){
for(var k in person) if(person[k].indexOf(w)!=-1) return true;
return false
}
keywords.some(isSubstring)
It is case sensitive and does not take word boundaries into account.
2nd answer
Here the method is insensitive , and - .
var regex = new RegExp('\\b('+keywords.join('|')+')\\b','i');
function anyValueMatches( o, r ) {
for( var k in o ) if( r.test(o[k]) ) return true;
return false;
}
anyValueMatches(person,regex)
If any keywordscontains characters that have special meaning in RegExp, they must be escaped.
source
share