Skip to content

Instantly share code, notes, and snippets.

@DaveAtDog
Last active September 21, 2018 08:49
Show Gist options
  • Save DaveAtDog/11207429 to your computer and use it in GitHub Desktop.
Save DaveAtDog/11207429 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