JS中key-value存取

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zh854663752/article/details/80839402
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]);
    }
}

猜你喜欢

转载自blog.csdn.net/zh854663752/article/details/80839402
今日推荐