Duplicate
Duplicates an object - either shallow or deep
Method Signature
Arguments
Argument
Type
Required
Description
Default
object
any
true
Any object to duplicate
deep
boolean
false
Whether to deep copy the object or make a shallow copy (e.g. only the top level keys in a struct)
true
Examples
Changing a struct compared to changing its copy
myNewStruct
holds a reference to myStruct
so if you change myNewStruct
, myStruct
is changed accordingly as well, because they are the same struct just assigned to two variables.
In comparison myOtherNewStruct
is a copy so if you change myOtherNewStruct
, myStruct
stays untouched because with the duplicate, a new, unique structure with the same key-value pairs is created thus they do not share the same reference
Result: ahmet sun → ahmet sun → dolor sit
Additional Examples
Related
Last updated
Was this helpful?