Arrays and objects handle most data in JavaScript, but two built-in structures solve problems they handle badly: Set for unique values and Map for key-value pairs with any kind of key. If you have never reached for them, you are probably writing extra code to do what they do for free.
A Set stores only unique values. Add the same value twice and it is stored once. That makes it the simplest way to remove duplicates from an array, check membership, or track which items you have already seen.
const tags = ["js", "css", "js", "html", "css"]; const unique = [...new Set(tags)]; // ["js", "css", "html"] const seen = new Set(); seen.add("user-1"); console.log(seen.has("user-1")); // true A Map is like an object, but better in three ways: its keys can be anything — objects, functions, not just strings; it remembers insertion order; and it has a real size property instead of making you count keys by hand.
const prices = new Map(); prices.set("book", 199); prices.set("course", 499); console.log(prices.get("book")); // 199 console.log(prices.size); // 2 // Any value can be a key const userRoles = new Map(); userRoles.set({ id: 1 }, "admin"); So when should you use them? Use a Set whenever uniqueness matters — deduping lists, tracking visited items, filtering duplicates. Use a Map when your keys are not strings, when order matters, or when you add and remove entries frequently. Use a plain object when you have a fixed set of string keys, like a config object or a JSON response.
One more practical note: both are iterable, so they work naturally with for...of, spread, and array methods after converting with [...map.keys()] or [...set]. They are not exotic features — they are everyday tools that most codebases underuse.
