JS Built-ins
← Map53 / 55
MapforEachintermediate

Map forEach() β€” third arg is Map

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

The third argument to the callback is the Map itself.

Challenge: Verify that the callback receives the Map as the third argument.

πŸ’‘ Hints (1)
  • β€’ The third argument lets you reference the Map inside the callback