JS Built-ins
← Map32 / 55
Mapclearbeginner

Map clear() β€” returns undefined

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

clear() returns undefined.

Challenge: Verify that the return value of clear() is undefined.

πŸ’‘ Hints (1)
  • β€’ clear() returns undefined β€” it modifies the Map in place