function isSubstring(w){
for(var k in person) if(person[k].indexOf(w)!=-1) return true;
return false
}
keywords.some(isSubstring) // true if a value contains a keyword, else false
This is case-sensitive and does not respect word boundaries.
2nd Answer
Here's a way that is case-insensitive, and does respect word boundaries.
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) // true if a value contains a keyword, else false
If any keywords contain characters that have special meaning in a RegExp, they would have to be escaped.
personobject, split the string by words, then loop thekeywordsarray and compare, or useindexOf