在json对象中按值查找键名

时间:2015-10-10 10:21:42

标签: javascript jquery json node.js

我需要按值获取密钥名称。

Json对象:

 {
   None : 0,
   Public : 82001,
   Unclassified : 82002,
   Restricted : 82003,
   Confidential : 82004,
   Secret : 82005,
   TopSecret : 82006,
   Private : 82007
}

example : I have value 82004 , I want to get key name (Confidential);

1 个答案:

答案 0 :(得分:1)

var data = {
    None: 0,
    Public: 82001,
    Unclassified: 82002,
    Restricted: 82003,
    Confidential: 82004,
    Secret: 82005,
    TopSecret: 82006,
    Private: 82007
}


$.each(data, function (inx, val) {
    if (val === 82004) {
        console.log(inx)
    }

})

试试这个