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'); | |
mySet.forEach((value, index, set) => { | |
console.log(value, index, set); | |
}); | |
// 'a', 'a', mySet |
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); | |
mySet.add(2); | |
mySet.add(2); | |
console.log(mySet.has(5)); | |
// false | |
console.log(mySet.has(1)); | |
// true |
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(); | |
console.log(mySet.size); | |
// 0 | |
mySet.add(1); | |
mySet.add(2); | |
mySet.add(2); | |
console.log(mySet.size); |
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); | |
mySet.add(2); | |
mySet.add(3); | |
mySet.clear(); | |
mySet.add(4); |
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); | |
mySet.add(2); | |
mySet.delete(1); // true | |
mySet.delete(3); // false | |
console.log(...mySet); | |
// 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(1); | |
mySet.add(2); | |
mySet.add(2); | |
console.log(...mySet); | |
// 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
console.time('Array test'); | |
const arr = []; | |
const count = 10; | |
for (let i = 0; i < count; i++) { | |
arr.push(i); | |
} |
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
console.time('Set test'); | |
const set = new Set(); | |
const count = 10; | |
for (let i = 0; i < count; i++) { | |
set.add(i); | |
} |
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 mySetFromString = new Set('hello'); |
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 mySetFromArray = new Set([1, 2, 3]); |