JS: Map.prototype.forEach

By Xah Lee. Date: . Last updated: .

(new in ECMAScript 2015)

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 xx = new Map([["a", 1], ["b", 2]]);

const xout = xx.forEach((v, k) => {
 console.log(v, k);
});
/*
1 a
2 b
*/

// returns undefined
console.assert(xout === undefined);
mapObj.forEach(f, thisArg)

Use thisArg for this (binding) of f. If it is not given, undefined is used.

JavaScript. Loop, Iteration

JS Map.prototype