Sidechair

array.pop()

Browse the reference

Removes the last item of an array and returns it.

Try it in the editor

The array becomes one item shorter and the other items keep their positions. With array.push() it forms a stack: the item you pushed last is the first one you pop.

Popping an empty array stops the script with an error saying there is nothing to pop. Guard with array.size() when that is possible.

Syntax

Pine Script
array.pop(id: any array type) -> series <type>
array.pop() -> series <type>

Arguments

NameTypeDefaultDescription
idany array typerequiredThe array to take the last item from. The item is removed and returned.

Returns

series <type>: The item that was removed.

Remarks

Example

Pine ScriptUndo the last stored swingOpen in editor
//@version=6
indicator("array.pop: swing stack", overlay = true)
var swings = array.new_float()
ph = ta.pivothigh(high, 5, 5)
if not na(ph)
    array.push(swings, ph)
if array.size(swings) > 3
    array.pop(swings)
plot(array.size(swings), "Swings held")

See also

Runs on Sidechair