Created
March 13, 2021 11:23
-
-
Save NovoManu/07dd0eb13aa883c89f31042306d52bb1 to your computer and use it in GitHub Desktop.
This file contains 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
// Set - collection with unique values | |
const set = new Set() | |
const john = 'John' | |
const diana = 'Diana' | |
const kate = 'Kate' | |
set.add(john) | |
set.add(diana) | |
set.add(kate) | |
console.log(set.size) // Expected output: 3 | |
set.add(john) | |
set.add(diana) | |
set.add(kate) | |
// Set can have only unique values and do nothing with duplicates | |
console.log(set.size) // Expected output: 3 | |
// It could be useful to clear array from duplicates | |
const arr = [1,2,3,4,1,2,3,4,5,6,7,8] | |
const noDuplicates = Array.from(new Set(arr)) | |
console.log(noDuplicates) // Expected output: [1, 2, 3, 4, 5, 6, 7, 8] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment