-
-
Save davidofug/ad58d27012c07e6fd7161951fd2a9e22 to your computer and use it in GitHub Desktop.
JavaScript — Find key for value in an object
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
var findKey = function(obj, value) | |
{ | |
var key = null; | |
for (var prop in obj) | |
{ | |
if (obj.hasOwnProperty(prop)) | |
{ | |
if (obj[prop] === value) | |
{ | |
key = prop; | |
} | |
} | |
} | |
return key; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment