Lodash _.cloneDeep() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Lang

Definition

Like _.clone, but recursively clones value so nested arrays and objects are new references too. Part of Lodash 4.x Lang.

Note: Deep cloning walks the whole graph — prefer _.clone when you only need a new top-level shell and will not mutate nests.

Syntax

Call _.cloneDeep. Start with this line.

Lodash
_.cloneDeep(value)
CallWhat it does
_.cloneDeep(value)Primary signature.

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

Library declarations
Lodash
_.cloneDeep(value)

Parameters

ParameterDescription
valueRequired. Value to deep-clone

Return Value

Return ValueDescription
*New deep copy (primitives as-is)

Lodash Examples

Example 1 — Official: Deep Array Clone

New array shell and new element objects.

Lodash
var objects = [{ a: 1 }, { b: 2 }];
var deep = _.cloneDeep(objects);

console.log(deep[0] === objects[0]);
// → false

console.log(deep === objects);
// → false
Try It Yourself

How It Works

  1. Outer. A new array is created.
  2. Inner. Each object element is cloned recursively.
  3. Identity. deep[0] === objects[0] is false.
  4. Safe. Mutating deep[0].a leaves objects[0] alone.

Example 2 — Nested Edit Stays Private

Changing a deep property does not leak to the source.

Lodash
var source = { a: 1, b: { c: 2 } };
var copy = _.cloneDeep(source);

copy.b.c = 99;

// source.b.c → 2
// copy.b === source.b → false
Try It Yourself

How It Works

  1. Deep walk. b is cloned into a new object.
  2. Edit. copy.b.c = 99 only hits the copy.
  3. Source. Still 2.
  4. Contrast. With _.clone, this edit would change both.

Example 3 — Nested Arrays

Inner arrays are copied too — not just the outer list.

Lodash
var rows = [[1], [2]];
var copy = _.cloneDeep(rows);

copy[0].push(9);

// rows → [[1], [2]]
// copy → [[1, 9], [2]]
// copy[0] === rows[0] → false
Try It Yourself

How It Works

  1. Outer. New top-level array.
  2. Inner. Each nested array is cloned.
  3. push. Extends only copy[0].
  4. Rule. Deep clone treats arrays like objects — recursively.

Example 4 — cloneDeep vs clone

Same source; only deep clone isolates the nest.

Lodash
var source = { b: { c: 1 } };
var shallow = _.clone(source);
var deep = _.cloneDeep(source);

shallow.b === source.b; // → true
deep.b === source.b;    // → false
Try It Yourself

How It Works

  1. clone. Copies the outer object only.
  2. cloneDeep. Also copies b.
  3. Compare. Deep’s nested object is a different reference.
  4. Pick. Nested edits → deep. Top-level only → shallow.

Example 5 — Flat Object (Deep Still Works)

On flat data, deep and shallow behave the same for edits.

Lodash
var source = { x: 1, y: 2 };
var copy = _.cloneDeep(source);

copy.x = 9;

// source.x → 1
// copy.x   → 9
Try It Yourself

How It Works

  1. No nests. Only primitives to copy.
  2. Edit. Top-level change is isolated either way.
  3. Cost. Deep clone adds little here — but prefer _.clone for clarity.
  4. Rule. Reach for deep when nests exist (or might later).

Browser & Runtime Support

_.cloneDeep is a Lodash 4.x Lang helper. It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 4.x

_.cloneDeep()

Available in [email protected] full builds and the lodash/cloneDeep modular import. Modern runtimes also offer structuredClone() for many built-in types; Lodash remains useful for consistent Lodash-style cloning and older environments.

100% With Lodash 4.x
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
_.cloneDeep Lodash 4.x+

Bottom line: Safe for production once Lodash is loaded. Prefer import cloneDeep from "lodash/cloneDeep" for smaller bundles. Use deep clone when nested mutations must stay private.

Frequently Asked Questions

_.cloneDeep(value) recursively clones value so nested arrays and objects are new references — mutations on the copy do not affect the source tree.
clone only copies the top level and shares nested refs. cloneDeep walks the whole graph and copies nested values too.
No. It builds a separate deep copy and leaves the source unchanged.
Use shallow clone when you only change top-level keys/indexes and will not mutate nested data — it is cheaper.
It can be. Cost grows with every nested node. Avoid deep-cloning huge graphs on hot paths.
Use import cloneDeep from "lodash/cloneDeep" or require("lodash/cloneDeep") for tree-shaking friendly bundles. Full build: import _ from "lodash" then _.cloneDeep.

Next: _.cloneDeepWith()

Deep-clone with a customizer for special nested values.

_.cloneDeepWith() 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.

10 people found this page helpful