Lodash _.flatMapDeep() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Collection

Definition

Like _.flatMap, but recursively flattens all nesting in the mapped results. Same idea as map + _.flattenDeep. Part of Lodash 4.x Collection (since 4.7.0).

Pass the required arguments shown below. Lodash Collection helpers usually return a new value — check whether the source is mutated.

Syntax

Call _.flatMapDeep on a collection. Start with this line.

Lodash
_.flatMapDeep(collection, [iteratee=_.identity])
CallWhat it does
_.flatMapDeep(collection, [iteratee=_.identity])Primary signature.
_.flatMapDeep(collection)Call with a collection argument.

Prefer import flatMapDeep from "lodash/flatMapDeep" when you want a smaller bundle.

Library declarations
Lodash
_.flatMapDeep(collection, [iteratee=_.identity])

Parameters

ParameterDescription
collectionRequired. Array or object to iterate
iterateeOptional. Maps each value; default _.identity

Return Value

Return ValueDescription
*New fully flattened array

Lodash Examples

Example 1 — Official: Triple-Wrapped Pairs

Return [[[n, n]]]; deep flatten to a single list.

Lodash
function duplicate(n) {
  return [[[n, n]]];
}

_.flatMapDeep([1, 2], duplicate);
// → [1, 1, 2, 2]
Try It Yourself

How It Works

  1. Iteratee. Each number is wrapped three array layers deep.
  2. Map. Produces [[[[1,1]]], [[[2,2]]]] shape before deep flatten.
  3. Recurse. Every array layer unwraps until numbers remain.
  4. Result. Four leaf values in one array.

Example 2 — Mixed Nesting Per Item

Scalars and nested arrays in the same iteratee return value.

Lodash
_.flatMapDeep([1, 2], function (n) {
  return [n, [n + 10]];
});
// → [1, 11, 2, 12]
Try It Yourself

How It Works

  1. For 1. [1, [11]] → leaves 1 and 11.
  2. For 2. [2, [12]] → leaves 2 and 12.
  3. Deep. The inner [n+10] arrays unwrap fully.
  4. Order. Leaves keep left-to-right encounter order.

Example 3 — _.flatMap vs _.flatMapDeep

Same iteratee; only flatten depth differs.

Lodash
function nest(n) {
  return [[n, n]];
}

_.flatMap([1, 2], nest);
// → [[1, 1], [2, 2]]

_.flatMapDeep([1, 2], nest);
// → [1, 1, 2, 2]
Try It Yourself

How It Works

  1. Iteratee. Returns [[n, n]] — two layers.
  2. flatMap. Removes one layer → pairs stay nested.
  3. flatMapDeep. Removes every layer → numbers only.
  4. Pick. Use Deep when nesting depth is unknown or uneven.

Example 4 — Deep Flatten Object Values

Plain objects are mapped by value, then flattened deeply.

Lodash
_.flatMapDeep({ a: [1, [2]], b: [[3, 4]] }, function (vals) {
  return vals;
});
// → [1, 2, 3, 4]
Try It Yourself

How It Works

  1. Values. Lodash walks a then b.
  2. Identity-like. Iteratee returns each nested array as-is.
  3. Deep flatten. [1,[2]] and [[3,4]] become leaves.
  4. Result. One numeric list in enumeration order.

Example 5 — Scalar Results Stay Leaves

Non-arrays are not wrapped — they appear once in the flat list.

Lodash
_.flatMapDeep([1, 2, 3], function (n) {
  return n % 2 === 0 ? [[[n, n * 10]]] : n;
});
// → [1, 2, 20, 3]
Try It Yourself

How It Works

  1. Odd. Returns scalar n → one leaf.
  2. Even. Returns [[[n, n*10]]] → deep-unwrapped to two leaves.
  3. Mix. Scalars and nested arrays can share one call.
  4. Guard. Objects (non-arrays) are leaves too — they are not walked.

Browser & Runtime Support

_.flatMapDeep is a Lodash 4.x Collection helper (added in 4.7.0). It runs anywhere Lodash 4.7+ runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Native Array.flatMap only flattens one level.

✓ Stable · Lodash 4.7+

_.flatMapDeep()

Available in [email protected]+ full builds and the lodash/flatMapDeep modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 4.7+
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.flatMapDeep Lodash 4.7+

Bottom line: Safe for production on Lodash 4.7+. Prefer import flatMapDeep from "lodash/flatMapDeep" for smaller builds. There is no native recursive flatMap — use Lodash or map + flat(Infinity).

Frequently Asked Questions

_.flatMapDeep(collection, iteratee) maps each element through iteratee, then recursively flattens all nested arrays in the results into one flat array.
No. It returns a new array. The source collection is left unchanged.
_.flatMap flattens only one level after mapping. _.flatMapDeep keeps flattening until no nested arrays remain.
Use _.flatMapDepth when you know a maximum depth and want to avoid fully collapsing very deep structures.
Scalars and objects are appended as single items. Only arrays are flattened recursively.
_.flatMapDeep was added in Lodash 4.7.0. It is stable in Lodash 4.x.

Next: _.flatMapDepth()

Same map idea, but stop flattening after a depth you choose.

_.flatMapDepth() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

7 people found this page helpful