JS Built-ins
← Map35 / 55
Mapclearbeginner

Map clear() β€” size before vs after

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

Use Map.clear() to remove all key-value pairs from the map.

Map.prototype.clear()

size goes from non-zero to zero after clear().

Challenge: Verify that size changes from 3 to 0 after clear().

πŸ’‘ Hints (1)
  • β€’ clear() always resets the Map to an empty state