Skip to content

Instantly share code, notes, and snippets.

@JoshOldenburg
Created April 20, 2014 02:03
Show Gist options
  • Save JoshOldenburg/11103014 to your computer and use it in GitHub Desktop.
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
_.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;
},
});
@JoshOldenburg
Copy link
Author

http://underscorejs.org/#find is the original _.find method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment