19 lines
430 B
JavaScript
19 lines
430 B
JavaScript
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));
|
|
|