Skip to content

Function: copy()

copy<T>(obj): T

Defined in: object.ts:17

Returns a deep clone of the given object. The clone is fully independent — modifying it will not affect the original.

Type Parameters

T

T

Parameters

obj

T

The object to clone.

Returns

T

A deep clone of the object.

Example

ts
const original = { name: 'Alice', scores: [1, 2, 3] }
const clone = copy(original)
clone.scores.push(4)
console.log(original.scores) // [1, 2, 3] — unchanged