Appearance
clone
Deep clones an array or object.
NOTE
Dates, maps, sets and regular expressions are cloned as themselves. Class instances are not - they are copied as plain objects, and circular references are not supported.
Usage
Arrays
ts
import { clone } from 'tsu'
const array = [1, 2, 3]
const clonedArray = clone(array)
// clonedArray: [1, 2, 3]
array === clonedArray
// falseObjects
ts
import { clone } from 'tsu'
const object = { frog: 'good' }
const clonedObject = clone(object)
// clonedObject: { frog: 'good' }
object === clonedObject
// falseDates, maps, sets and regular expressions
ts
import { clone } from 'tsu'
const map = new Map([['frog', { sound: 'ribbit' }]])
const clonedMap = clone(map)
clonedMap.get('frog')
// { sound: 'ribbit' }
clonedMap.get('frog') === map.get('frog')
// falseType Definitions
ts
/**
* @param input - The array or object to clone.
* @returns A deep clone of the input array or object.
*/
function clone<T>(input: T): T