Returns a clone, also known as a deep copy, of a variable
or XML object. There is no reference to the original variable.

duplicate(variable) → returns any

duplicate Argument Reference

variable any

Examples sample code invoking the duplicate function

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

myStruct = {'foo': 'Lorem ipsum', 'bar': 'baz'};

myNewStruct = myStruct;
myOtherNewStruct = duplicate(myStruct);

myNewStruct.foo = 'ahmet sun';
myOtherNewStruct.foo = 'dolor sit';

writeOutput(myStruct.foo&' → '&myNewStruct.foo&' → '&myOtherNewStruct.foo);

Expected Result: ahmet sun → ahmet sun → dolor sit

Fork me on GitHub