Like _.cloneWith, except it recursively clones value. Your customizer can replace any visited node; return undefined to keep Lodash’s default deep-clone path. Part of Lodash Lang since 4.0.0 (stable — not deprecated). Note: the customizer runs for many nodes — keep it cheap.
Pass the value you want to inspect or convert. Read the return type carefully before you use the result.
Syntax
Call _.cloneDeepWith. Start with this line.
Lodash
_.cloneDeepWith(value, [customizer])
Call
What it does
_.cloneDeepWith(value, [customizer])
Primary signature.
_.cloneDeepWith(value)
Check, compare, clone, or convert a value.
Prefer import cloneDeepWith from "lodash/cloneDeepWith" when you want a smaller bundle.
Library declarations
Lodash
_.cloneDeepWith(value, [customizer])
Parameters
Parameter
Description
value
Required. Value to recursively clone
customizer
Optional. Hook that may replace any visited node
Return Value
Return Value
Description
*
Deep-cloned value (customized where you returned a value)
Lodash Examples
Example 1 — Transform Nested Numbers
Return a value from the customizer to replace that node in the clone.
Lodash
var source = { a: 1, nest: { b: 2 } };
var copy = _.cloneDeepWith(source, function (value) {
if (typeof value === "number") {
return value * 2;
}
});
console.log(copy);
// → { a: 2, nest: { b: 4 } }
Hook. Customizer returns undefined for every node.
Fallback. Lodash deep-clones objects and arrays normally.
Independence.copy.nest is a new object — not the same reference.
Safe mutate. Changing the clone leaves the source at 1.
Example 3 — Keep the Same Function Reference
Reuse function identity instead of cloning (functions are not usefully deep-cloned).
Lodash
var id = function (x) { return x; };
var source = { scale: 2, fn: id };
var copy = _.cloneDeepWith(source, function (value) {
if (typeof value === "function") {
return value; // same reference
}
});
console.log(copy.fn === source.fn); // true
console.log(copy.scale); // 2
Shallow.cloneWith copies only the top level → nest is shared.
Deep.cloneDeepWith recurses → nest is a new object.
Customizer. Both accept the same hook style; depth is the difference.
Pick. Need nested independence? Prefer cloneDeepWith.
Compatibility
Browser & Runtime Support
_.cloneDeepWith is a Lodash 4.x Lang helper (since 4.0.0). It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Native engines have structuredClone, but not this customizer-based deep clone by name.
✓ Stable · Lodash 4.0.0+
_.cloneDeepWith()
Available in [email protected] full builds and the lodash/cloneDeepWith 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
_.cloneDeepWithLodash 4.0.0+
Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import cloneDeepWith from "lodash/cloneDeepWith" for smaller builds. Not a native browser API — load Lodash first.
Frequently Asked Questions
_.cloneDeepWith(value, [customizer]) is like _.cloneWith, but it recursively clones value. Your customizer can replace any visited node; return undefined to keep Lodash’s default deep-clone behavior for that node.
If the customizer returns undefined, Lodash applies its normal deep-cloning logic for that value. Return any other value to use it as the cloned result for that node.
No. It builds a new structure from cloning rules and your customizer. The original value is left unchanged.
cloneDeep always uses Lodash’s built-in deep rules. cloneDeepWith adds a customizer hook so you can override cloning for Dates, DOM nodes, functions, or other special values.
cloneWith is shallow — nested objects stay shared unless you replace them. cloneDeepWith recurses through the whole tree with the same customizer pattern.
Use import cloneDeepWith from "lodash/cloneDeepWith" or require("lodash/cloneDeepWith") so bundlers can tree-shake unused Lodash code. Full build: import _ from "lodash" then _.cloneDeepWith.