JS Built-ins
← Map11 / 55
Mapsetbeginner

Map set() β€” returns same Map

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

set() adds or updates a key-value pair and returns the Map itself, enabling chaining.

Challenge: Verify that map.set('a', 1) returns the same map instance.

πŸ’‘ Hints (1)
  • β€’ set() returns the Map itself, making chaining possible