var json = {"america":"1234","india":"5678","britain":"789"};
function getValueByKey(obj, val) {
// Looping on object keys
return Object.keys(obj).filter(function (key) {
return obj[key] === val
})[0];
}
// For testing
console.log(getValueByKey(json, "1234")); // america
console.log(getValueByKey(json, "5678")); // india
1条答案
按热度按时间4ioopgfo1#