This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myMap = new Map([[1, 11]]); | |
console.log(myMap.get(1)); // 11 | |
console.log(myMap.get(2)); // undefined |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myMap = new Map(); | |
myMap | |
.set('k1', 1) | |
.set('k2', 2); | |
for (let item of myMap) { | |
console.log(item); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myMap = new Map(); | |
myMap.set('k1', 1); | |
myMap.set('k1', 2); | |
console.log([...myMap]); | |
// [ ['k1', 2] ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myMap = new Map([['key1', 'val1'], [2, 'val2'], [2, 'val3']]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myMap = new Map([['key1', 'val1'], [2, 'val2']]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
count | Array Test, usign includes | Array test, using indexOf | Set Test, using has | |
---|---|---|---|---|
10 | 0.23095703125ms | 0.188720703125ms | 0.409912109375ms | |
100 | 0.230712890625ms | 0.197998046875ms | 0.390869140625ms | |
1000 | 0.236083984375ms | 0.206787109375ms | 0.38916015625ms | |
10000 | 0.09033203125ms | 0.11083984375ms | 0.278076171875ms | |
100000 | 0.123046875ms | 0.134033203125ms | 0.166015625ms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
count | Array Time | Set Time | |
---|---|---|---|
10 | 0.0478515625ms | 0.02001953125ms | |
100 | 0.160888671875ms | 0.033935546875ms | |
1000 | 1.44775390625ms | 0.4873046875ms | |
10000 | 46.619140625ms | 6.260986328125ms | |
100000 | 3247.35888671875ms | 36.764892578125ms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mySet = new Set(); | |
mySet | |
.add(1) | |
.add(2); | |
for (let val of mySet) { | |
console.log(val); | |
} | |
// 1, 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mySet = new Set(); | |
mySet.add('a'); | |
mySet.add('b'); | |
const mySetKeysArray = [...mySet.keys()]; | |
const mySetValuesArray = [...mySet.keys()]; | |
/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mySet = new Set(); | |
mySet.add('a'); | |
mySet.add('b'); | |
const mySetEntriesArray = [...mySet.entries()]; | |
/* | |
[ | |
['a', 'a'], |