Skip to content

cloneDeep

Clone the given object and possibly other objects nested inside. By default, the only objects that get cloned are plain objects, class instances, arrays, `Set` instances, and `Map` instances. If an object is not cloned, any objects nested inside are also not cloned. You may define a custom cloning strategy by passing a partial implementation of the `CloningStrategy` interface to the `cloneDeep` function. Any undefined methods will fall back to the default cloning logic. Your own methods may return null to indicate that the default cloning logic should be used. They may also return the input object to indicate that cloning should be skipped. const obj = { a: 1, b: { c: 2 } } const clone = cloneDeep(obj) assert(clone !== obj) assert(clone.b !== obj.b) assert(JSON.stringify(clone) === JSON.stringify(obj))

Installation

Terminal window
npx atmx add helper clone-deep