Invokes an iteratee for each element in a collection (array or object). Callbacks receive (value, index|key, collection). Return false to stop early. Alias: _.each. Part of Lodash 4.x Collection.
Pass the required arguments shown below. Lodash Collection helpers usually return a new value — check whether the source is mutated.
Syntax
Call _.forEach on a collection. Start with this line.
Lodash
_.forEach(collection, [iteratee=_.identity])
Call
What it does
_.forEach(collection, [iteratee=_.identity])
Primary signature.
_.forEach(collection)
Call with a collection argument.
Prefer import forEach from "lodash/forEach" when you want a smaller bundle.
Library declarations
Lodash
_.forEach(collection, [iteratee=_.identity])
Parameters
Parameter
Description
collection
Required. Array or object to iterate
iteratee
Optional. Called per element; default _.identity
Return Value
Return Value
Description
*
The original collection
Lodash Examples
Example 1 — Official: Array Values
Visit each number left to right.
Lodash
var logged = [];
_.forEach([1, 2], function (value) {
logged.push(value);
});
// logged → [1, 2]
Style. Prefer one name in a codebase for consistency.
Compatibility
Browser & Runtime Support
_.forEach is a Lodash 4.x Collection helper (alias _.each). It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Native Array.prototype.forEach is ES5 but cannot early-exit with false.
✓ Stable · Lodash 4.x
_.forEach()
Available in [email protected] full builds and the lodash/forEach modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.
100%With Lodash 4.x
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
_.forEachLodash 4.x+
Bottom line: Safe for production once Lodash is loaded. Prefer import forEach from "lodash/forEach" for smaller builds. Use Lodash when you need early exit or object collections.
Frequently Asked Questions
_.forEach(collection, iteratee) calls iteratee once per element. Arguments are (value, index|key, collection). It returns the original collection.
Return false from the iteratee. Lodash then stops visiting further elements. Native Array.forEach cannot break this way.
Not by itself. Your callback might mutate elements or nested objects — keep side effects intentional.
Use forEach for side effects (log, accumulate outside, DOM). Use _.map when you need a new array of transformed values.
_.each is an alias of _.forEach — same behavior.
Lodash may treat them like arrays. For own enumerable keys only, prefer _.forOwn or _.forIn.