JS Built-ins
← Map34 / 55
Mapclearbeginner

Map clear() β€” clear empty Map is fine

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

Calling clear() on an already empty Map is safe and does nothing.

Challenge: Verify that clearing an empty Map doesn't throw.

πŸ’‘ Hints (1)
  • β€’ clear() is safe to call on an empty Map