Skip to content

Instantly share code, notes, and snippets.

@premasagar
Created June 3, 2010 21:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save premasagar/424508 to your computer and use it in GitHub Desktop.
Save premasagar/424508 to your computer and use it in GitHub Desktop.
Pluck an object that contains a key and optional value
// Pluck an object that contains a key and optional value
function getBy(enumerable, findProperty, findValue){
return jQuery.map(enumerable, function(el){
if (typeof el[findProperty] !== 'undefined'){
if (typeof findValue === 'undefined' ||
el[findProperty] === findValue){
return el;
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment