Array.prototype.forEach() - JavaScript | MDN

developer.mozilla.org

Tin mới

HTML: Markup language

See all HTML references

Date & time formats

See all HTML guides

CSS: Styling language

See all CSS references

See all CSS guides

Centering an element

JavaScript: Scripting language

Standard built-in objects

Expressions & operators

Statements & declarations

See all JavaScript references

Control flow & error handing

Loops and iteration

Working with objects

See all JavaScript guides

Web APIs: Programming interfaces

Service worker API

Using the Web animation API

Using the Fetch API

Working with the History API

Using the Web speech API

All web technology

Progressive web apps

Learn web development

Getting started modules

Structuring content with HTML module

CSS styling basics module

Dynamic scripting with JavaScript module

Border-image generator

Border-radius generator

Box-shadow generator

Color format converter

promise composition

The forEach() method is an iterative method. It calls a provided callbackFn function once for each element in an array in ascending-index order. Unlike map(), forEach() always returns undefined and is not chainable. The

arrow function expression

Note: If passing the callback function used an arrow function expression, the thisArg parameter could be omitted, since all arrow functions lexically bind the this value.

Array.prototype.flat()

The following example is only here for learning purpose. If you want to flatten an array using built-in methods, you can use Array.prototype.flat().

Indexed collections

Array.prototype.find()

Array.prototype.map()

Array.prototype.filter()

Array.prototype.every()

Array.prototype.some()

TypedArray.prototype.forEach()

Map.prototype.forEach()

Set.prototype.forEach()

Learn how to contribute

This page was last modified on May 22, 2026 by MDN contributors.

[Symbol.iterator]()

[Symbol.unscopables]

[Symbol.hasInstance]()