Last active
September 21, 2018 08:49
-
-
Save DaveAtDog/11207429 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