[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach [Back]  [Original]

Map.prototype.forEach() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Map.prototype.forEach()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.

Map forEach() Map / .

In this article

function logMapElements(value, key, map) {
  console.log(`m[${key}] = ${value}`);
}

new Map([
  ["foo", 3],
  ["bar", {}],
  ["baz", undefined],
]).forEach(logMapElements);

// Expected output: "m[foo] = 3"
// Expected output: "m[bar] = [object Object]"
// Expected output: "m[baz] = undefined"

js
forEach(callbackFn)
forEach(callbackFn, thisArg)

callbackFn

. .

value

.

key

.

map

Map .

thisArg Optional

callbackFn this .

(undefined).

forEach callback . . undefined callback .

callback 3 .

  • value
  • key
  • Map

thisArg forEach this callback . undefined this . callback this this .

forEach . callback . forEach .

Map

Map .

js
function logMapElements(value, key, map) {
  console.log(`map.get('${key}') = ${value}`);
}
new Map([
  ["foo", 3],
  ["bar", {}],
  ["baz", undefined],
]).forEach(logMapElements);
// Logs:
// "map.get('foo') = 3"
// "map.get('bar') = [object Object]"
// "map.get('baz') = undefined"

Specification
ECMAScript 2027 LanguageSpecification
# sec-map.prototype.foreach


Web Proxy Viewer  |  New URL  |  Original Page