Sidechair

map.remove()

Browse the reference

Deletes a pair by key and returns the value it held, or na when the key was not there.

Try it in the editor

The other pairs keep their order. Removing a missing key is not an error; it just returns na.

Use the returned value to act on what was removed, or ignore it.

Syntax

Pine Script
map.remove(id: any map type, key: series <type of the map's elements>) -> <value_type>
map.remove(key: series <type of the map's elements>) -> <value_type>

Arguments

NameTypeDefaultDescription
idany map typerequiredThe map to take a pair out of. A key that is not there leaves it as it is.
keyseries <type of the map's elements>requiredThe key whose pair is removed. It has to match the key type of the map.

Returns

<value_type>: The removed value, or na.

Example

Pine ScriptExpire an entryOpen in editor
//@version=6
indicator("map.remove: expire", overlay = false)
var open_ = map.new<int, float>()
if bar_index % 10 == 0
    map.put(open_, bar_index, close)
if map.contains(open_, bar_index - 30)
    map.remove(open_, bar_index - 30)
plot(map.size(open_), "Entries held")

See also

Runs on Sidechair