Favorites

JavaScript Map.prototype.forEach() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Map.prototype.forEach()
JavaScript Map Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

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, key and the map.

Return Value

None (undefined).

Example

const ages = new Map([['Sam', 30], ['Alex', 25]]);
ages.forEach((age, name) => console.log(name, age));

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.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee