clone
objectCreates a deep clone of value. Supports cloning arrays, objects, Date, RegExp, Map, and Set.
Signature
clone<T>(value: T): TParameters
| Name | Type | Description |
|---|---|---|
value | T | The value to clone |
Returns
T - Returns the cloned value
Examples
Basic Usage
import { clone } from 'dashlite'
const obj = { a: 1, b: { c: 2 } }
const cloned = clone(obj)
cloned.b.c = 3
console.log(obj.b.c)Output:
2With Date
import { clone } from 'dashlite'
const date = new Date('2024-01-01')
const cloned = clone(date)
console.log(cloned instanceof Date)Output:
trueAvailable since version 1.0.0