JavaScript: Map.prototype.forEach

By Xah Lee. Date: . Last updated: .

New in JS2015.

map_obj.forEach(f)
  • Apply function f to all entries in map map_obj in the order the entries are inserted. Does not modify the map object.
  • Return undefined.
  • f is passed 3 arguments: value, key, map_obj. 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);
map_obj.forEach(f, thisArg)
Use thisArg for this Binding of f. If it is not given, undefined is used.

See also: Iterate Over Map Object

BUY
ΣJS
JavaScript in Depth

JS Obj Reference

Map

prototype