Sets
A Set stores each value only once. Use add, has, delete and size. Turning an array into a Set is the quickest way to remove duplicates.
Example
const tags = new Set(["js", "css", "js", "html"]);
console.log(tags.size);
tags.add("python");
console.log(tags.has("css"));
console.log([...tags]);
const unique = [...new Set([1, 1, 2, 3, 3])];
console.log(unique);Exercise
Create a new Set.
const s = Set([1, 2]);
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.