Tsallaka zuwa abun ciki
Justice Tech School

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

What happens when you add the same value to a Set twice?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.