Edit: Remove jQuery and fix case-sensitivity problem. Note, this is no longer compatible with IE8 due to the use of map()
, forEach()
and indexOf()
on Array.prototype
.
Something along these lines would do the trick:
var names = ['John', 'Joe', 'Ralph'],
data = [
{
id: 1,
name: 'John'
},
{
id: 2,
name: 'Joseph'
},
{
id: 3,
name: 'ralph'
}
],
results = [];
var lnames = names.map(function(name) {
return name.toLowerCase();
});
data.forEach(function(item) {
if (lnames.indexOf(item.name.toLowerCase()) > -1) {
results.push(item.id);
}
});
console.log('found: ', results);
Here's a live example: http://jsfiddle.net/6ptz3/2/