Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015년 7월.
Map 인스턴스의 forEach() 메서드는 이 Map 객체의 키/값 쌍마다 각각 제공된 함수를 삽입되었던 순서대로 실행합니다.
맵의 각 항목에 대해 실행할 함수입니다. 이 함수는 다음 인수를 사용하여 호출됩니다.
value각 반복의 값입니다.
key각 반복의 키입니다.
map반복되는 Map 입니다.
thisArg OptionalcallbackFn을 실행하고 있을 때 this로 사용하는 값.
없음 (undefined).
forEach 메서드는 실제로 존재하는 맵의 각 키에 대해 제공된 callback을 한 번씩 실행합니다. 삭제된 키에 대해서는 호출되지 않습니다. 그러나 값은 존재하지만 undefined값일 경우에는 callback이 실행됩니다.
callback은 인자 3개와 함께 호출됩니다.
thisArg가 forEach의 매개 변수로 제공되면 호출 시 this 값으로 사용하기 위해 callback에 전달됩니다. 그렇지 않으면 undefined 값이 this 값으로 사용되도록 전달됩니다. callback이 궁극적으로 관찰할 수 있는 this 값은 함수가 보는 this를 결정하기 위한 일반적인 규칙에 따라 결정됩니다.
forEach가 완료되기 전에 삭제했다가 다시 추가한 경우를 제외하고 각 값은 한 번씩 방문합니다. 방문하기 전에 삭제된 값에 대해서는 callback이 호출되지 않습니다. forEach가 완료되기 전에 추가된 새 값은 나중에 방문합니다.
다음 코드는 Map 객체에서 각 요소의 내용을 한 줄의 로그로 남깁니다.
| ECMAScript® 2027 Language Specification # sec-map.prototype.foreach |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025년 2월 11일 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.