Loop Through Array Items in n8n Without Breaking Your Flow

Looping through array items in n8n is one of the most common requirements in building automated workflows. Whether you're parsing API responses, iterating over rows in a Google Sheet, or processing multiple records from a database, knowing how to loop through array items in n8n efficiently can save you time and make your automations more powerful. The best part? You can do it without writing any code and without breaking your flow.

Let’s walk through how to loop properly in n8n, share common use cases, and include a beginner-friendly step-by-step setup.


Why Looping in n8n Matters

In n8n, almost every node outputs data as an array of items. If you don’t process them correctly, your workflow may either bulk-handle everything in one go (which isn’t always what you want) or fail entirely.

Understanding how the SplitInBatches and Item Lists nodes work will open up your ability to build dynamic automations that process one item at a time, trigger sub-workflows intelligently, and handle errors without losing control.


Method 1: Using the SplitInBatches Node (Most Common)

What is SplitInBatches?

The SplitInBatches node allows you to iterate over each item in an array individually. It’s a control node that temporarily pauses execution for one item at a time until you manually trigger the next run.

Step-by-Step: Loop Over Array Items Using SplitInBatches

Let’s assume you have an HTTP Request node that returns an array of user data.

  1. Start with your trigger
    This could be any trigger: webhook, cron, or manual.

  2. Add the node that returns the array
    For example, an HTTP Request pulling data from a CRM API, such as a list of subscribers.

  3. Add a SplitInBatches node
    Place it after the HTTP Request node. Configure it as:

    • Batch Size: 1 (to process each item one by one)
  4. Add processing logic
    Following SplitInBatches, add the workflow logic to handle individual items. For example, send an email, write to a database, or call another API.

  5. Use Loop Logic
    Link another SplitInBatches node to your last node and enable the loop:

    • Continue On Fail: Enabled
    • Connect the “Continue” output to the top of the SplitInBatches to re-enter the loop.
  6. Use the "No More Items" exit
    Optionally, from the SplitInBatches “No More Items” output, you can send a notification or log the batch is complete.

Simple Visual Flow

[HTTP Request] → [SplitInBatches] → [Send Email] → [Back to SplitInBatches]
                                                 ↓
                                            [Final Step]

This setup allows your workflow to process each array item sequentially without overwhelming external services like email clients or APIs.


Method 2: Using the Item Lists Node (for Nested or Filtered Data)

The Item Lists node is useful when you want to pre-process your data array: trim columns, filter values, or split complex fields.

Use Case Example

Let’s say you have an array of orders, but you only want to loop through those where status = 'pending'.

  1. Add an IF node after the HTTP Request or data source.
  2. Set the condition to status equals pending.
  3. Only pass filtered items to the SplitInBatches node.
  4. The rest of the loop logic remains the same.

This allows you to avoid processing unnecessary data and avoids bloated workflows.

For more about managing branching logic, refer to the full guide to n8n triggers, which explains splitting and filtering inputs with nodes like IF and Switch.


Mini Use Case: Sending a Custom Email to Each Form Submission

Let’s say you received 10 form responses via Webhook, and you want to send each responder a personalized thank-you email.

Workflow Steps:

  • Webhook (collect the form responses)
  • HTTP Request (optional: fetch additional user data)
  • SplitInBatches (looping over each submission)
  • Set Node (construct personalized email message using {{ $json["name"] }})
  • Gmail / SMTP Node (send email)
  • Loop back to SplitInBatches to continue for the next item.

This method adapts well for lead nurturing, onboarding emails, and custom notifications.


Tips to Avoid Errors While Looping

1. Handle Empty Arrays Gracefully

Always check if the array has data before entering a loop. You can add an IF node before SplitInBatches to verify $items.length > 0.

2. Use Default Expression Editor

To refer to specific properties of the current item, use:

{{ $json["fieldName"] }}

This works well inside Set nodes or HTTP params during each iteration.

3. Monitor Workflow Run Times

Loops can slow down your workflow, especially if you’re waiting on external APIs. Consider adding delay nodes or executing sub-workflows in parallel if required.

If errors during loop execution are a concern, you might want to read about mastering error handling in n8n for retry and alert logic.


Bonus: Looping Without SplitInBatches (For Advanced Users)

You can also use Function or Execute Workflow nodes to handle iterations yourself. This approach is ideal when you want greater control, such as:

  • Concurrent processing
  • Recursive loops
  • External break conditions

However, for the majority of users, SplitInBatches will be the most effective low-code solution.


Summary Table: SplitInBatches vs Item Lists

Feature SplitInBatches Item Lists
Processes one item at a time ✅ Yes ❌ No (used for preprocessing)
Supports looping ✅ Yes (manual loop setup) ❌ No
Ideal for email sending / API limits
Filters or flattens arrays ❌ Use with IF Node ✅ Yes

FAQ

How to loop through array items in n8n using no-code?

Use the SplitInBatches node. Set the batch size to 1 to process one item at a time, and use a loop to re-enter the SplitInBatches node until no items remain.

Can I use a Function node instead of SplitInBatches?

Yes, advanced users can write custom JavaScript in the Function node to process arrays using for or forEach loops. But for most tasks, SplitInBatches offers a safer and no-code approach.

What happens if my array is empty?

n8n will skip the SplitInBatches loop entirely if there are no items. You can add an IF node before it to check for array length and decide whether to proceed.

Can I process array items in parallel in n8n?

Not natively in the same loop. For true parallelism, you can trigger sub-workflows using the Execute Workflow node and set them to run asynchronously.

Why is my SplitInBatches loop not iterating?

Ensure your loop is properly configured. The final output of your loop logic must reconnect back to SplitInBatches. Also, check that Batch Size is set and that you haven't filtered out all items earlier in the workflow.


Need more visual options for no-code automation? See our n8n vs Make: A visual comparison for choosing the right platform depending on your use case.

Or, if you're looking to scale this setup to handle data from Google Sheets, Calendars, or Drive, check out how to connect Google apps with n8n to expand your automation toolkit.

★★★★★
50+ fixes, templates & explanations
Stuck with n8n errors?
Node-by-node breakdown.
Copy-paste templates.
Beginner friendly.
Get the n8n Beginners Guide
Built by AgentForEverything.com
Comments
Join the Discussion and Share Your Opinion
Add a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Newsletter
Get The Latest Agent Templates & Guides, Straight To Your Inbox.
Join the #1 AI Automation newsletter.