JS Built-ins
← Map33 / 55
Mapclearbeginner

Map clear() β€” has() false after clear

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

After clear(), has() returns false for all previously existing keys.

Challenge: Verify that has() returns false after clear().

πŸ’‘ Hints (1)
  • β€’ After clear(), the Map is completely empty