# Foreach

Foreach action is just a more readable way of handling iteration over an array. Only thing to keep in mind is that **Iterate over** is JavaScript expression, if you want to reference data from other actions you need to use **ctx** object. **Iterator variable** on the other hand is not an expression but is just a name for output value that will be stored in **ctx** object.

<figure><img src="/files/IusXOz36xUCXxk1Rc5Rk" alt=""><figcaption></figcaption></figure>

### Iterator variable

Iterator variable is not an expression but a name for where to store the currently iterating item. With above example first item will be `ctx.product = ctx.products[0]` and so on for each iteration.


---

# 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.syncmate.com/getting-started/actions/foreach.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.
