in_groups_of

Converts an array into array of subarrays. Each subarray is going to have n elements.

{% json ar %}
[1,2,3,4,5,6,7,8,9]
{% endjson %}

{% assign in_groups = ar | in_groups_of: 2 %}
{{in_groups | log }}

As a result in_groups variable contains following array: [[1,2], [3,4], [5,6], [7,8], [9]]

Last updated