Stores a value under a key, adding the pair or replacing the old value, and returns the previous value.
If the key is new, a pair is added at the end of the map's order and the call returns na. If the key exists, its value is replaced in place and the old value is returned.
Adding a pair that would take the map past 50,000 pairs stops the script with an error.
Syntax
map.put(id: any map type, key: series <type of the map's elements>, value: series <type of the map's elements>) -> <value_type>
map.put(key: series <type of the map's elements>, value: series <type of the map's elements>) -> <value_type>Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | any map type | required | The map that stores the pair. A key that is already there gets the new value. |
| key | series <type of the map's elements> | required | The key to look up or store. It has to match the key type of the map. |
| value | series <type of the map's elements> | required | The value to store. It has to match the value type of the map. |
Returns
<value_type>: The value that was stored under the key before, or na when the key was new.
Remarks
- The return value is easy to ignore;
map.put(m, k, v)works as a plain statement.
Example
//@version=6
indicator("map.put: last close by hour", overlay = false)
var lastClose = map.new<int, float>()
prev = map.put(lastClose, hour, close)
plot(close - nz(prev, close), "Change since this hour last time")See also
Runs on Sidechair