-
-
Save ldong/07104bcb8e7b86f4e8c8 to your computer and use it in GitHub Desktop.
Find key by value, with underscore.js
This file contains hidden or 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, 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