Removes the last item of an array and returns it.
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
array.pop(id: any array type) -> series <type>
array.pop() -> series <type>Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | any array type | required | The array to take the last item from. The item is removed and returned. |
Returns
series <type>: The item that was removed.
Remarks
- To take from the front instead, use
array.shift().
Example
//@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