push
Appends an element to the end of an array. The original array is modified (mutated) with the new element added.
{% json items %}[1, 2, 3, 4]{% endjson %}
{% push items, 5 %}
{% log items %}
{% comment %} Output: [1, 2, 3, 4, 5] {% endcomment %}Syntax
{% push array_name, element %}Parameters
array_name
Yes
The array to add the element to
element
Yes
The value to append (literal or variable)
Behavior
Adds the element to the end of the array
Modifies the original array (mutation)
Element can be any type: string, number, object, array, or variable
Supports nested array access with dot notation
Examples
Push a literal value:
Push a variable:
Push an object:
Build array in a loop:
Collect filtered items:
Push to nested array:
Stack implementation with push and pop:
Collect errors during processing:
Build comma-separated string from array:
Aggregate data from API calls:
Related Tags
pop
Removes and returns the last element (LIFO)
Notes
The array must exist and be a valid array, otherwise an error is thrown
Push modifies the original array in place
Useful for building arrays dynamically during script execution
Works with the Liquid
| push:filter, but the tag version supports complex valuesSupports dot notation for nested arrays (e.g.,
data.items)No limit on the number of elements that can be pushed
Last updated