Nested array.[{ id: 2 }] unwraps because depth allows it.
Leaf object.{ id: 2 } is not an array → not “opened” further.
Rule. Flattening is about array wrappers, not object trees.
Compatibility
Browser & Runtime Support
_.flattenDepth is a Lodash 4.x Array helper (added in 4.4.0). It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash.
✓ Stable · Lodash 4.4.0+
_.flattenDepth()
Available in [email protected] full builds and the lodash/flattenDepth modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.
100%With Lodash 4.4.0+
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
_.flattenDepthLodash 4.4.0+
Bottom line: Safe for production once Lodash 4.4.0+ is on the page or in your bundle. Prefer import flattenDepth from "lodash/flattenDepth" for smaller builds. Native alternative on real arrays: Array.prototype.flat(depth) (ES2019).
Frequently Asked Questions
_.flattenDepth(array, depth) recursively flattens nested arrays up to depth times and returns a new array. Deeper nesting than depth can remain.
When depth is omitted, Lodash defaults to 1 — the same idea as _.flatten for ordinary nested arrays.
flattenDeep keeps unwrapping until no arrays remain. flattenDepth stops after exactly the depth you pass, which may leave nested arrays in the result.
No. It returns a new array. Leaf objects and any arrays that survive flattening still share references with the source.
A depth of 0 returns a shallow copy of the array without removing any nesting — useful when you want the same API but no flattening.
Use import flattenDepth from "lodash/flattenDepth" or require("lodash/flattenDepth") for tree-shaking friendly bundles. Full build: import _ from "lodash" then _.flattenDepth.