JS中key-value存取

var map = {};
map['key1'] = 1;
map['key2@'] = 2;
 
console.log(map['key1']);//结果是1.
console.log(map['key2@']);//结果是2.
 
//如果遍历map
for(var prop in map){
    if(map.hasOwnProperty(prop)){
        console.log('key is ' + prop +' and value is' + map[prop]);
    }

  

posted @ 2021-01-09 13:58  八英里  阅读(316)  评论(0编辑  收藏  举报