HomeToolsAbout

Set

What is it

Set objects are collection of values.

  • Value in set may only occur once and is unique in the set's collection.

Creating Set

// Create a Set const someSet = new Set(["a","b"]);

Adding item to Set

const someSet = new Set(["a","b"]); // adding element someSet.add("c"); console.log(someSet); // ["a","b","c"] // adding existing element someSet.add("c"); console.log(someSet); // ["a","b","c"]

Checking if item exists in set

const someSet = new Set(["a","b"]); someSet.has("a"); // true someSet.has("d"); // false
AboutContact