Skip to content

Instantly share code, notes, and snippets.

@gsans
Created February 23, 2015 19:14
Show Gist options
  • Save gsans/85d6a099023a6682f63f to your computer and use it in GitHub Desktop.
Save gsans/85d6a099023a6682f63f to your computer and use it in GitHub Desktop.
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