Skip to content

Instantly share code, notes, and snippets.

@ldong
Forked from mxriverlynn/findkey.js
Last active September 4, 2015 05:33
Show Gist options
  • Save ldong/07104bcb8e7b86f4e8c8 to your computer and use it in GitHub Desktop.
Save ldong/07104bcb8e7b86f4e8c8 to your computer and use it in GitHub Desktop.
Find key by value, with underscore.js
function findKey(obj, value){
var key;
_.each(_.keys(obj), function(k){
var v = obj[k];
if (v === value){
key = k;
}
});
return key;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment