Map & Set essentials
Use Map for key→value lookups and Set for unique values; iterate, convert, and apply tiny patterns.
Why Map & Set?
Goal: Pick the right container.
- Map: key→value (any type of key)
- Set: unique values
- Iterate and convert
- Tiny everyday patterns

Map: set/get/has
Map offers set, get, has, delete, clear, and a size property.
// Map: key→value with any key type
const userToScore = new Map();
// set values
userToScore.set("ayla", 10);
userToScore.set("mina", 15);
// read values
console.log("ayla:", userToScore.get("ayla"));
console.log("has lena?", userToScore.has("lena"));
// size
console.log("size:", userToScore.size);

All lessons in this course
- Map & Set essentials
- WeakMap & WeakSet — simple privacy and caches
- Iteration Patterns