JQuery native function for this filter :
$(data).filter(function(){ return this.id == "foo"; });
It is shorter than the code you have, and, more importantly, much more readable. As for efficiency, it will iterate over all the elements in the set to find as many matches as possible, but I hardly believe that this will be the neck of the bottle of your application, not focus on microoptimization .
I suggest you read Eric Lipper's blog about It's Faster .
You can also use grep as suggested by @Mattias Buelens:
$.grep(data, function(ele){ retun ele.id == "foo"; });
source share