Skip to content
Justice Tech School

Set and Map in Practice

Set stores unique values and Map stores key value pairs with any key type. Both keep insertion order and have size, has, add or set, delete and forEach.

Example
const set = new Set([1, 2, 2, 3]);
console.log(set.size, [...set]);
const map = new Map([["a", 1]]);
map.set("b", 2);
console.log(map.get("b"), map.has("c"), [...map.keys()]);

Exercise

Remove duplicates.

[...new (arr)]

Quiz Test

What is special about Set?

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