Created
February 23, 2015 19:14
-
-
Save gsans/85d6a099023a6682f63f 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
let x = new Set([1, 2, 3, 4, 4, 4, 5]); | |
x.add(6); | |
x.delete(2); | |
console.log('The set contains', x.size, 'elements.'); | |
console.log('The set has 1:', x.has(1)); | |
console.log('The set has 8:', x.has(8)); | |
//values and keys are the same in a set | |
x.forEach((value, key, set) => console.log(value, key, set)); | |
//iterable | |
for (let value of x) { | |
console.log(value); | |
} | |
//iterable values | |
for (let value of x.values()) { | |
console.log(value); | |
} | |
//iterable keys | |
for (let value of x.keys()) { | |
console.log(value); | |
} | |
//iterable entries (key, value) | |
for (let value of x.entries()) { | |
console.log(value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment