Skip to main content

cloneDeep()

cloneDeep<T>(value): T

Creates a deep clone of a value using the native structuredClone API.

DEPRECATED

Use the native structuredClone() function directly instead.


Type Parameters​

T: T​

The type of the value to clone.


Parameters​

value: T​

The value to clone deeply.


Returns: T​

A deep clone of the input value.


See Also​


Since​

2.0.0


Also known as​

clone (Remeda, Ramda) · cloneDeep (Lodash, es-toolkit, Radashi) · ❌ (Effect, Modern Dash, Antfu)


Example​

const original = { a: 1, b: { c: 2 } };

// ❌ Deprecated approach
const cloned = cloneDeep(original);
cloned.b.c = 3;
console.log(original.b.c); // 2 (unchanged)

// βœ… Recommended approach
const clonedNative = structuredClone(original);
clonedNative.b.c = 3;
console.log(original.b.c); // 2 (unchanged)

How it works?​

Creates a deep clone of a value. Deprecated: Use structuredClone() directly (ES2022) or Arkhe's deepClone.

Native Equivalent​

// ❌ cloneDeep(obj)
// βœ… structuredClone(obj)
// βœ… deepClone(obj) // Arkhe

Use Cases​

Deep copy object πŸ“Œβ€‹

Create deep copy of object.

structuredClone(obj);
// or
JSON.parse(JSON.stringify(obj));

Immutable updates​

Clone before modifying.

const newState = structuredClone(state);
newState.user.name = "New Name";

Isolate data​

Create independent copy.

const copy = structuredClone(original);
// Modifications don't affect original