Skip to content

Instantly share code, notes, and snippets.

@jslnriot
Created December 12, 2022 02:09
Show Gist options
  • Save jslnriot/2e9cf374da575e1bdad3f56aa5e2962f to your computer and use it in GitHub Desktop.
Save jslnriot/2e9cf374da575e1bdad3f56aa5e2962f to your computer and use it in GitHub Desktop.
// create a new set
let mySet = new Set();
// add some values to the set
mySet.add(1);
mySet.add("hello");
mySet.add({x: 10, y: 20});
// check if a value is in the set
console.log(mySet.has(1)); // true
console.log(mySet.has("hello")); // true
console.log(mySet.has({x: 10, y: 20})); // false (object equality is not checked)
// get the number of values in the set
console.log(mySet.size); // 3
// remove a value from the set
mySet.delete("hello");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment