JS Built-ins
← Map54 / 55
MapforEachbeginner

Map forEach() β€” empty Map is fine

πŸ“– Usage Example
const m = new Map([['a', 1], ['b', 2]])
m.forEach((val, key) => console.log(key, val))
// 'a' 1, then 'b' 2

Use Map.forEach() to execute a callback for each key-value pair in the map.

Map.prototype.forEach()

Calling forEach on an empty Map does not invoke the callback.

Challenge: Verify that forEach on an empty Map calls the callback 0 times.

πŸ’‘ Hints (1)
  • β€’ forEach on an empty Map is a no-op