Skip to content

Instantly share code, notes, and snippets.

@davidofug
Forked from DaveAtDog/findKey.js
Created June 16, 2018 12:47
Show Gist options
  • Save davidofug/ad58d27012c07e6fd7161951fd2a9e22 to your computer and use it in GitHub Desktop.
Save davidofug/ad58d27012c07e6fd7161951fd2a9e22 to your computer and use it in GitHub Desktop.
JavaScript — Find key for value in an object
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