Creates a deep clone of the provided value.
Recursively copies all properties of objects and elements of arrays, ensuring that nested objects and arrays are also cloned. Primitives are returned as-is.
The type of the value to clone.
The value to deep clone (object, array, or primitive).
A deep clone of the input value.
// ES Moduleimport { deepClone } from '@bnidev/js-utils'// CommonJSconst { deepClone } = require('@bnidev/js-utils') Copy
// ES Moduleimport { deepClone } from '@bnidev/js-utils'// CommonJSconst { deepClone } = require('@bnidev/js-utils')
const original = { a: 1, b: { c: 2 } }const cloned = deepClone(original)console.log(cloned) // Output: { a: 1, b: { c: 2 } }// Modifying the clone does not affect the originalcloned.b.c = 3console.log(original.b.c) // Output: 2 Copy
const original = { a: 1, b: { c: 2 } }const cloned = deepClone(original)console.log(cloned) // Output: { a: 1, b: { c: 2 } }// Modifying the clone does not affect the originalcloned.b.c = 3console.log(original.b.c) // Output: 2
Creates a deep clone of the provided value.
Recursively copies all properties of objects and elements of arrays, ensuring that nested objects and arrays are also cloned. Primitives are returned as-is.