# 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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.datajet-app.com/liquid/filters/in_groups_of.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
