【整理】【JS】map的基本操作
// 1、定义 var map = {1: "a", 2: "b", c: "3"}; // 2、遍历 for (key in map) { console.log(key + ":" + map[key]); } console.log("=================添加==================="); // 3、添加 map["d"] = "ee"; for (key in map) { console.log(key + ":" + map[key]); } console.log("=================替换==================="); // 4、替换 map["c"] = "444"; for (key in map) { console.log(key + ":" + map[key]); } console.log("=================删除==================="); // 5、删除 map.hasOwnProperty("1") ? delete map["1"] : 0; for (key in map) { console.log(key + ":" + map[key]); }