Skip to main content
Mastra v1 is coming in January 2026. Get ahead by starting new projects with the beta or upgrade your existing project today.

Workflow.foreach()

The .foreach() method creates a loop that executes a step for each item in an array.

Usage exampleDirect link to Usage example

workflow.foreach(step1, { concurrency: 2 });

ParametersDirect link to Parameters

step:

Step
The step instance to execute in the loop. The previous step must return an array type.

opts?:

object
Optional configuration for the loop. The concurrency option controls how many iterations can run in parallel (default: 1)
number

ReturnsDirect link to Returns

workflow:

Workflow
The workflow instance for method chaining

On this page