-
-
Save roaldjap/5470908c67d33ca6de45945410e4865b 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