@bnidev/js-utils
    Preparing search index...

    Function deepClone

    • 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.

      Type Parameters

      • T

        The type of the value to clone.

      Parameters

      • obj: T

        The value to deep clone (object, array, or primitive).

      Returns T

      A deep clone of the input value.

      // ES Module
      import { deepClone } from '@bnidev/js-utils'

      // CommonJS
      const { 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 original
      cloned.b.c = 3
      console.log(original.b.c) // Output: 2