map init
This commit is contained in:
parent
d9bba74979
commit
564631b29b
18
5.6Map/t.js
Normal file
18
5.6Map/t.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
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));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user