JS 的Map() 方法 使用

 var m = new Map(); //new一个对象 ,键值唯一
m.set(1, "aaaaaaa"); // 添加值
m.set(2, "dddddd");
 m.set("h", [1,4,3,5,6,]);
m.set("sex", 2);
m.set({a:2}, 3);
 m.set({a:2}, 3);// 只会输出一个来
//遍历打印效果,期待吧~~

m.forEach(function (item, key, mapObj) {
   console.log(item);
   console.log(key);
  console.log(mapObj);
});  
ss-
发布了20 篇原创文章 · 获赞 7 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/month_ss_815/article/details/80196927