Skip to content

Instantly share code, notes, and snippets.

@richardcpeterson
Created September 9, 2011 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardcpeterson/1206868 to your computer and use it in GitHub Desktop.
Save richardcpeterson/1206868 to your computer and use it in GitHub Desktop.
JavaScript function to select from array of objects
function select (a) {
return {
from : function (b) {
return {
where : function (c) {
return {
equals : function (d) {
var foo = [];
for (prop in b){
if (b[prop][c] == d){
foo.push(b[prop][a]);
}
}
return foo;
},
contains : function (d) {
var foo = [];
for (prop in b){
if (b[prop][c].indexOf(d) != -1){
foo.push(b[prop][a]);
}
}
return foo;
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment