Last active
August 29, 2015 14:21
-
-
Save MNBuyskih/3be329c2c8a3287b9e00 to your computer and use it in GitHub Desktop.
UnderscoreJS find key in object by predicant
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
function findKey (obj, predicant) { | |
var key = null; | |
_.find(obj, function (v, k) { | |
if (predicant(v, k, obj)) { | |
key = k; | |
return true; | |
} | |
return false; | |
}); | |
return key; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment