JS Built-ins
← Map12 / 55
Mapsetbeginner

Map set() β€” get 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()

After calling set(key, value), get(key) returns that value.

Challenge: Verify that get('a') returns 1 after set('a', 1).

πŸ’‘ Hints (1)
  • β€’ set() stores the value and get() retrieves it by key