JS Built-ins
← Map13 / 55
Mapsetbeginner

Map set() β€” overwrite value

πŸ“– 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()

Calling set() with an existing key overwrites the old value.

Challenge: Verify that setting the same key twice gives the new value.

πŸ’‘ Hints (1)
  • β€’ Setting an existing key updates the value; the size stays the same