• Clones an object or array.

    Note: This works only for flat objects not for objects which are instances of classes.

    Note: Cycles in obj are not supported for now.

    Type Parameters

    • T extends any[] | Record<any, any> | Primitive

      the type of the input object to clone

    Parameters

    • obj: T

      Object or array to clone.

    Returns T

    import clone from "apprt-core/clone";

    const src = {x: 1, y: { a: 2 } };
    const copy = clone(src);
    src === copy // -> false
    src.y === copy.y // -> false
    copy.y.a // -> 2