Returns a new map with the same pairs, so changes to one map no longer affect the other.
The copy is shallow: if the values are objects, both maps still point at the same objects. For numbers, strings and colors the two maps are fully independent.
Take a copy before experimenting with a map that other code reads.
Syntax
map.copy(id: any map type) -> map<keyType, valueType>
map.copy() -> map<keyType, valueType>Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | any map type | required | The map to duplicate. The copy holds the same pairs and is a separate map. |
Returns
map<keyType, valueType>: A new map with the same key and value types and pairs.
Example
//@version=6
indicator("map.copy: snapshot", overlay = false)
var live = map.new<string, float>()
map.put(live, "close", close)
snap = map.copy(live)
map.put(live, "close", close * 2)
plot(map.get(snap, "close"), "Snapshot")
plot(map.get(live, "close"), "Live")See also
Runs on Sidechair