JavaScript Map.prototype.forEach() Method
The forEach() method runs a function for each entry of a Map, in insertion order.
Description
The forEach() method calls a function once for each entry, in insertion order. Note the argument order: the value comes first, then the key. A for...of loop over map (which gives [key, value] pairs) is often clearer.
An optional second argument sets the value of this inside the callback, although arrow functions make that rarely necessary. Entries added during the loop are visited if they come after the current position, and deleted entries that haven't been reached are skipped.
Unlike a for...of loop, forEach() can't be stopped early with break, and it doesn't wait for async callbacks.
Syntax
map.forEach(callbackFn)Parameters
- callbackFnA function called for each entry with
value,keyand the map.
Return Value
None (undefined).
Example
Browser Support
The following information will show you the current browser support for the Map.prototype.forEach() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





