Answers for "find the key of a value javascript"

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

find the key of a value in array js

Object.keys(array).find(item => array[item].id === modifiedItem.id)
Posted by: Guest on October-12-2021

Code answers related to "find the key of a value javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language