Created
June 3, 2010 21:18
-
-
Save premasagar/424508 to your computer and use it in GitHub Desktop.
Pluck an object that contains a key and optional value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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