Removes and returns the last element from an array. Modifies the original array in place.
{% assign last_item = my_array | pop %} {% log last_item %}
{{ array | pop }}
array
Array to remove the last element from
Returns the removed element. The original array is shortened by one element.
Pop the last element:
{% assign colors = "red,green,blue" | split: "," %} {% assign last = colors | pop %} {% log last %} {% log colors %}
Output:
blue ["red", "green"]
Process items from the end:
Use with the pop tag for named assignment:
Modifies the original array — the popped element is removed permanently
Returns the input unchanged if it is not an array
There is also a {% pop array as variable %} tag that does the same thing with a clearer syntax
{% pop array as variable %}
See also: push
push
Last updated 5 months ago
{% assign stack = "first,second,third" | split: "," %} {% assign item = stack | pop %} {% log "Processing: " | append: item %} {% log "Remaining: " | append: stack.size %}
{% pop my_array as last_element %} {% log last_element %}