This question already has answers here:
Getting JSON Key from Value or Inverting JSON Data
                                
                                    (2个答案)
                                
                        
                                4年前关闭。
            
                    
我需要按值获取键名。

杰森对象:

 {
   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);

最佳答案

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)
    }

})


试试这个

10-08 03:21