concat

Concatenates two arrays together or appends elements to an array. Returns a new array without modifying the original arrays.

{% assign fruits = "apple,banana" | split: "," %}
{% assign more_fruits = "cherry,date" | split: "," %}

{% assign all_fruits = fruits | concat: more_fruits %}
{% log all_fruits | join: ", " %}

Output:

apple, banana, cherry, date

Syntax

{{ array | concat: other_array }}
{{ array | concat: element }}
Parameter
Description

array

The base array

other_array

Array to append, or single element to add

Examples

Combine two arrays:

{% assign domestic_orders = orders | where: "shipping_country", "US" %}
{% assign international_orders = orders | where: "shipping_country", "CA" %}

{% assign north_america_orders = domestic_orders | concat: international_orders %}

{% log "Total North America orders: " | append: north_america_orders.size %}

Build array from multiple sources:

Merge GraphQL pagination results:

Combine tags from multiple products:

Add single element to array:

Merge line items from multiple orders:

Combine API responses:

Build notification recipients:

Comparison: concat vs push

Feature

concat

push

Modifies original

No (returns new array)

Yes (mutates in place)

Can add arrays

Yes (flattens one level)

No (adds array as single element)

Use case

Merging arrays

Adding single items

Example difference:

Performance Tip

When building large arrays in a loop, concat creates a new array each time. For better performance with many iterations, consider using push which modifies in place:

Notes

  • Returns a new array; original arrays are not modified

  • When concatenating arrays, elements are flattened one level deep

  • When concatenating a single value, it's added as-is

  • Works with any array types (strings, numbers, objects)

  • For adding single items in a loop, prefer push for better performance

  • See also: push for in-place array modification

Last updated