I have an array of about 950 objects, each containing basic information about soccer players for me to list on the page. I'm adding search functionality to this wherein I check the "name" key in each object and return similar results. This code snippet assumes I have an empty array for the results (results = []), and obvs I'm looping using underscore (see: lodash):
_.each(players, function(player, i){
if(player.name.search(searchString) !== -1){
results.push(item);
}
})
This works well, but takes FOREVER. Okay it actually takes about 1 second but it more or less destroys the browser and eats memory like chocolate cake while it's running and is a very sluggish UX.
The ask: Is there a better way to do this (better == quicker)?
I can put my actual data in a jsfiddle/jsbin/jswhatever if that helps.