js uses a for-in loop to traverse (key-value) objects, and reads the value according to the key value

var MSG={
    
    
process_success :{
    
    code:200,msg:"Success"},
service_unavailable :{
    
    code:5031001,msg:"Server exception"},
wrong_url : {
    
    code:4041001,msg:"Wrong url"},
}

How to get the code:

for(var e in MSG){
    
    
    console.log(MSG[e].code)
    
}

I didn’t touch the front end for half a year, and I forgot the basic skills. I cried.

Guess you like

Origin blog.csdn.net/weixin_43361722/article/details/112626470