• Creates a shallow clone of an object or array.

    For primitive values, returns the value as-is. For objects and arrays, creates a new instance with the same properties or elements.

    Type Parameters

    • T

      The type of the object to clone.

    Parameters

    • obj: T

      The object to clone.

    Returns T

    A shallow clone of the object.

    import { clone } from './AcCmLodashUtils'

    const original = { a: 1, b: 2 }
    const cloned = clone(original)
    cloned.a = 3
    console.log(original.a) // 1 (unchanged)
    console.log(cloned.a) // 3

    const arr = [1, 2, 3]
    const clonedArr = clone(arr) // [1, 2, 3]