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

你可能感兴趣的:(JS 的Map() 方法 使用)