Skip to content

cloneDeep

Creates a deep copy of an object or array.

Recursively clones own enumerable string keys. Date instances are reconstructed with the same epoch value. Prototype-polluting keys (__proto__, constructor, prototype) are silently skipped. Does not handle circular references.

Limitation: symbol-keyed own properties are not copied — only string keys are processed. Use structuredClone if symbol propagation is required.

Available since v1.9.0

import { cloneDeep } from '@helpers4/object';
// or, from the all-in-one package (same code, one install):
import { cloneDeep } from 'helpers4/object';
cloneDeep<T>(obj: T): T
ParameterTypeDescription
objTThe value to clone

T — A deep copy of obj

Creates a deep copy — modifying the clone does not affect the original.

const original = { a: { b: 1 } };
const cloned = cloneDeep(original);
cloned.a.b = 2;
// original.a.b is still 1

View source on GitHub