JS: Map.prototype.forEach

By Xah Lee. Date: . Last updated: .

New in ES2015.

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.

If thisArg is given, it will be used as this value of f. If it is not given, undefined is used.

[see JS: “this” Binding]

The function f is passed 3 arguments: value, key, map_object.

Note the order of the value/key.

const mm = new Map( [["a", 1], ["b",2] ]);

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

// returns undefined
console.log( rr === undefined ); // true

See also: JS: Iterate Over Map Object

JS Map

  1. the Map Object Tutorial
  2. Iterate Over Map Object
  3. Convert Object to/from Map
  4. Map Filter
  5. Reverse Key/Value

Like it? Help me by telling your friends. Or, Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials