> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fastgen.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Loop data

**Iterate over each element in a collection.**

<img src="https://mintcdn.com/organa/x4VcIWGQE6pfuZkY/images/loop-data-flow-control-header.webp?fit=max&auto=format&n=x4VcIWGQE6pfuZkY&q=85&s=d8902e03dac8a0cdd1e2ac8f10144869" alt="loop-data-flow-control-header" width="2431" height="1356" data-path="images/loop-data-flow-control-header.webp" />

## Overview

The Loop Data action is designed to iterate over each element in a provided collection,executing the defined actions for each element.

### Accessing Action Output within a Loop

When you use actions inside a For Loop, each action's output can be accessed as if it were an array. This feature allows you to retrieve data from any specific iteration of the loop.

To access the output of an action in a specific iteration, use the following syntax:

* For a fixed iteration (e.g., the first iteration): `{{$action.actionName[0].outputField}}`
* For the last iteration: `{{$action.actionName[-1].outputField}}`

Here, `actionName` is the name of the action, and `outputField` is the specific field in the output you want to access. The index `0` refers to the first iteration, `1` for the second, and so on. The index `-1` always refers to the last iteration.

Learn more about this syntax and indexing variables in our [Variables Documentation](/variables/overview).

### Example

<img width="450" src="https://mintcdn.com/organa/x4VcIWGQE6pfuZkY/images/loop-data-example.webp?fit=max&auto=format&n=x4VcIWGQE6pfuZkY&q=85&s=6c37fc098a69f9c2971d6a75e36685d8" data-path="images/loop-data-example.webp" />

### Output

```json theme={null}
{
  "$action['loop-customers']": {
    "i": 2, // Last run iteration of the loop
    "item": "Joe" // Last run item of the collection
  }
}
```
