Answers for "how to get the key of a certain property in an object"

15

how to find the key of an value in an object

function getKeyByValue(object, value) {
  return Object.keys(object).find(key => object[key] === value);
}


const map = {"first" : "1", "second" : "2"};
console.log(getKeyByValue(map,"2"));
Posted by: Guest on August-07-2020
1

js find value of property and return it's key

const getKeyByValue = (obj, value) => 
        Object.keys(obj).find(key => obj[key] === value);
Posted by: Guest on April-23-2021

Code answers related to "how to get the key of a certain property in an object"

Code answers related to "Javascript"

Browse Popular Code Answers by Language