var.dup

var dup() const @safe

Create a deep copy of this var.

For scalar types (NULL, BOOL, numeric, CHAR, WCHAR, DCHAR, STRING), this returns a simple copy since these are value types or immutable.

For container types (ARRAY, OBJECT), this recursively duplicates all elements, ensuring that modifications to the copy do not affect the original.

Returns

A new var that is a deep copy of this value.

Examples

var original;
original["nested"] = var([1, 2, 3]);
var copy = original.dup;
copy["nested"][0] = 99;
assert(original["nested"][0].as!int == 1); // original unchanged