let myMap = new Map();
myMap.set(0, "zero");
myMap.set(1, "one");
for (let [key, value] of myMap) {
console.log(key + " = " + value);
}
for (let key of myMap.keys()) {
console.log(key);
}
for (let value of myMap.values()) {
console.log(value);
}
for (let [key, value] of myMap.entries()) {
console.log(key + " = " + value);
}
let map = new Map([[], [], []])
我们想要把 对象 变为一个 map。
let obj = {
name: 'john'
}
let map = new Map(Object.entries(obj));
map.get('name'); // john
Object.entries 会返回 键/值对数组:[[], []]