📜  如何从javascript代码示例中的值获取键

📅  最后修改于: 2022-03-11 15:03:49.457000             🧑  作者: Mango

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


const map = {"first" : "1", "second" : "2"};
console.log(getKeyByValue(map,"2"));
 Run code snippetHide results