Created
April 20, 2014 02:03
-
-
Save JoshOldenburg/11103014 to your computer and use it in GitHub Desktop.
Underscore.js mixin which mimics _.find, except returning the key instead of the 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
_.mixin({ | |
findKey: function(obj, predicate, context) { | |
var result = null; | |
_.some(obj, function(value, index, list) { | |
if (predicate.call(context, value, index, list)) { | |
result = index; | |
return true; | |
} | |
}); | |
return result; | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://underscorejs.org/#find is the original
_.find
method