# in\_groups\_of

Splits an array into smaller arrays (chunks) of a specified size. Useful for batching API calls, paginating data, or processing items in fixed-size groups.

```liquid
{% assign batches = products | in_groups_of: 50 %}
{% for batch in batches %}
  {% log "Batch size: " | append: batch.size %}
{% endfor %}
```

#### Syntax

```liquid
{{ array | in_groups_of: size }}
```

| Parameter | Description                          |
| --------- | ------------------------------------ |
| `array`   | Array to split into groups           |
| `size`    | Maximum number of elements per group |

#### Return Value

Returns an array of arrays. Each inner array contains at most `size` elements. The last group may contain fewer elements if the array length is not evenly divisible.

#### Examples

**Batch API calls in groups of 10:**

```liquid
{% assign batches = product_ids | in_groups_of: 10 %}
{% for batch in batches %}
  {% assign ids = batch | join: "," %}
  {% log "Processing batch: " | append: ids %}
{% endfor %}
```

**Process GraphQL mutations in batches of 250:**

```liquid
{% assign batches = variants | in_groups_of: 250 %}
{% for batch in batches %}
  {% log "Batch " | append: forloop.index | append: " of " | append: batches.size | append: ": " | append: batch.size | append: " variants" %}
  {% comment %} Build and execute mutation for this batch {% endcomment %}
{% endfor %}
```

**Split CSV rows for parallel processing:**

```liquid
{% assign rows = file.content | parse_csv %}
{% assign chunks = rows | in_groups_of: 100 %}
{% for chunk in chunks %}
  {% run "process_chunk", data:chunk %}
{% endfor %}
```

**Paginate results:**

```liquid
{% assign pages = all_items | in_groups_of: 20 %}
{% log "Total pages: " | append: pages.size %}
{% assign current_page = pages[0] %}
{% for item in current_page %}
  {% log item.title %}
{% endfor %}
```

#### Notes

* The last group may be smaller than the specified size
* Returns an empty array if the input is empty
* Useful in combination with `run` to dispatch batched work asynchronously
