javascript-learner/5.6Map/t.js

19 lines
430 B
JavaScript
Raw Normal View History

2024-06-18 09:08:38 +02:00
let map = new Map();
map.set('1', 'first');
map.set(1, 'second');
map.set(true, 'third');
console.log(map.get('1'));
console.log(map.get(1));
console.log(map.get(true));
console.log(map.size);
// we should use the map.get() method, not map[] so that we can use the feature of the map, ot the map can only get the value from number and string
let person = {name: 'John'};
map.set(person, 'hi');
console.log(map.get(person));