JS Built-ins
← Map15 / 55
Mapsetbeginner

Map set() β€” size after set

πŸ“– Usage Example
const m = new Map()
m.set('a', 1)
m.set('b', 2)
console.log(m.size) // β†’ 2

Use Map.set() to add or update a key-value pair; it returns the map itself.

Map.prototype.set()

Each unique key added increases size by 1.

Challenge: Verify that size equals the number of unique keys set.

πŸ’‘ Hints (1)
  • β€’ Each unique key added with set() increases size by exactly 1