Skip to content

Instantly share code, notes, and snippets.

@mildfuzz
Created October 17, 2012 14:30
Show Gist options
  • Select an option

  • Save mildfuzz/3905826 to your computer and use it in GitHub Desktop.

Select an option

Save mildfuzz/3905826 to your computer and use it in GitHub Desktop.
getObjectByAttribute
Array.prototype.getObjectByAttribute = function(value, attribute){
var catcher = [], i = 0;
while(!catcher && this[i]){
if(this[i].attribute == value){
catcher.push(this[i]);
}
i++;
}
return catcher.length == 1 ? catcher[0] : catcher.length ? catcher : false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment