map.put() - Pine Script Function
map.put()
Section titled “map.put()”Overview
Section titled “Overview”Puts a new key-value pair into the id map.
Syntax
Section titled “Syntax”map.put(id, key, value) → <value_type>Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| id | any map type | A map object. |
Returns
Section titled “Returns”The previous value associated with key if the key was already present in the map, or na if the key is new.
Remarks
Section titled “Remarks”- Maps maintain insertion order. Note that the order does not change when inserting a pair with a key that’s already in the map. The new pair replaces the existing pair with the key in such cases.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6indicator("map.put example")a = map.new<string, float>()map.put(a, "first", 10)map.put(a, "second", 15)prevFirst = map.put(a, "first", 20)currFirst = a.get("first")plot(prevFirst)plot(currFirst)