标签:运算符 foreach 数据转换 log fine clear val people 添加
1 const peoples = new Map() 2 peoples.set(‘name‘, ‘L‘) 3 peoples.set(‘age‘, ‘25‘) 4 peoples.set(‘sex‘, ‘男‘) 5 console.log(peoples); 6 // {"name" => "L", "age" => "25", "sex" => "男"}
1 for (let key of peoples) { 2 console.log(key); // ["name", "L"] ["age", "25"] ["sex", "男"] 3 }
1 peoples.forEach((value, key, map) => { 2 console.log(value, key, map); 3 }); 4 // 输出:L name Map(3) {"name" => "L", "age" => "25", "sex" => "男"} 5 // 25 age Map(3) {"name" => "L", "age" => "25", "sex" => "男"} 6 // 男 sex Map(3) {"name" => "L", "age" => "25", "sex" => "男"}
1 var arr = [...peoples] 2 console.log(arr); 3 // 0: (2)["name", "L"] 4 // 1: (2)["age", "25"] 5 // 2: (2)["sex", "男"]
标签:运算符 foreach 数据转换 log fine clear val people 添加
原文地址:https://www.cnblogs.com/1825224252qq/p/11785635.html