clone

object

Creates a deep clone of value. Supports cloning arrays, objects, Date, RegExp, Map, and Set.

Signature

clone<T>(value: T): T

Parameters

NameTypeDescription
valueTThe 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:

2

With Date

import { clone } from 'dashlite'

const date = new Date('2024-01-01')
const cloned = clone(date)
console.log(cloned instanceof Date)

Output:

true

Available since version 1.0.0