JS: Map.prototype.forEach

By Xah Lee. Date: . Last updated: .

New in JS2015.

mapObj.forEach(f)
  • Apply function f to all entries in map mapObj in the order the entries are inserted. Does not modify the map object.
  • Return undefined.
  • f is passed 3 arguments: value, key, mapObj. Note the order in parameter is value first.
const mm = new Map([["a", 1], ["b", 2]]);

const rr = mm.forEach((v, k) => {
  console.log(v, k);
});
// 1 'a'
// 2 'b'

// returns undefined
console.log(rr === undefined);
mapObj.forEach(f, thisArg)
Use thisArg for this Binding of f. If it is not given, undefined is used.
BUY ΣJS JavaScript in Depth

JavaScript, Loop, Iteration