Skip to content

deepClone Deep Clone Tool

Function List

deepClone(source) => any

Deeply recursively clones an object or an array; modifications to the cloned object will not affect the original object.

Parameters

Parameter NameTypeRequiredDefaultDescription
sourceobject | any[]Yes-The object or array to be deeply cloned

Return Value

TypeDescription
anyThe new object or array after deep cloning

Example

typescript
import { deepClone } from '@hy-app/ui';

const oldObj = {
    name: 'Old Data',
};

const newObj = deepClone(oldObj);
newObj.name = 'New Data';

console.log(oldObj); // { name: "Old Data" }
console.log(newObj); // { name: "New Data" }