Js对象怎么通过value值拿到key值

var data = {
  a: 1,
  b: 'string',
  c: {},
  d: {a: 98, b: 'str'}
}

function findKey (value, compare = (a, b) => a === b) {
  return Object.keys(data).find(k => compare(data[k], value))
}

var val = data.b
findKey(val) // b
原文地址:https://www.cnblogs.com/luorende/p/13037169.html