How to Use Loop Over Items in n8n (With Examples)

I created an automation that explains how data flows and looping works within n8n. When building workflows, you often need to handle multiple items at once, whether those are rows from a spreadsheet or multiple results from an API call. Understanding how n8n manages these items and how to control the processing can make your automations much more efficient.

Understanding Data Flow and Internal Looping in n8n

In many workflows, you deal with multiple data items simultaneously. For example, if you pull data from a Google Sheet, you might retrieve several rows at once. When I tested a simple workflow that reads rows from a Google Sheet, n8n received three separate rows of data. These rows appear as individual data items, and n8n processes each one separately behind the scenes.

Google Sheets node returning multiple rows as separate data items

This internal handling means there’s already some looping happening without needing to add any explicit loop or split nodes. This built-in looping is very convenient because it simplifies workflows where you just want to process each row or item individually without extra setup.

In my example, I read data from a task list sheet and then passed it to another Google Sheets node to update rows in a different sheet. Within the Google Sheets append node, you can toggle between schema table and JSON views. When viewing the table, you’ll see three separate items, which you can map to fields in the destination sheet. By dragging in the title from the JSON, n8n processes each row individually and uploads them quickly, all handled internally.

Mapping multiple data items to Google Sheets fields

Handling Arrays of Items: When to Use the Split Out Node

Sometimes, you might receive multiple items bundled together as a single array. This often happens with manual triggers or certain API responses. In these cases, n8n does not automatically split the array into individual items. Instead, if you try to map the entire array directly into a Google Sheets node, the sheet will just receive the whole JSON array dumped into one row, which is rarely what you want.

Google Sheets dumping entire JSON array into one row

I encountered this common scenario and showed how to fix it using the Split Out node. This node takes an overall array and separates it into individual items that n8n can then process one by one. You simply drag the array field into the Split Out node, leaving other fields blank. When you test it, you’ll see the array transformed into separate items on the right-hand side of the node output.

Split Out node transforming array into separate items

Once you have these items split out properly, you can map fields like the task title into your Google Sheets node just as before. Testing the workflow again shows that the data updates row by row in Google Sheets correctly.

Google Sheets updated with split data items

One key detail is that n8n processes all items in a node before moving on to the next node. This differs from platforms like Make.com, which process the entire flow for each item sequentially. You might find it surprising that much of this works without even using the explicit Loop Over Items node, which I’ll explain next.

Introducing the Loop Over Items Node and Using AI in Workflows

Before adding the Loop Over Items node, I expanded the workflow to include an AI step. I added a basic LLM (Large Language Model) chain to categorize each task as either a video, blog post, or email. The prompt was simple to keep the example clear: “Categorize this task, respond with either video, blog post or email.”

LLM prompt to categorize task title

I linked the LLM chain to the split-out task titles, so each task was processed separately. The chain made three individual calls to the AI, one per item, before moving on. Then I connected the AI’s categorized result back into the Google Sheets node, mapping the category and task title fields.

Mapping AI results and task titles to Google Sheets

Running the workflow uploaded all the categorized rows to the sheet in one go. Initially, I made a small mistake by setting the category field as fixed text instead of an expression, but correcting that fixed the issue. This example demonstrates that you don’t always need the Loop Over Items node since n8n handles multiple items internally well in many cases.

When to Use the Loop Over Items Node: Rate Limiting and Batch Processing

There are definite cases where you want to use the Loop Over Items node. One common reason is rate limiting. If you have many items and call an external API for each one, you might hit request limits or get errors from too many simultaneous calls.

Loop Over Items node with batch size of one for rate limiting

By adding the Loop Over Items node and setting a batch size (for example, one item at a time), you can process items sequentially. This node loops through each item, allowing you to insert wait times between calls. I demonstrated this by linking the Loop Over Items node between the AI chain and the Google Sheets node, then adding a Wait node to pause for one second between each iteration.

Wait node added to Loop Over Items for delay between API calls

Running this workflow showed how the loop processed one item, updated the sheet, waited a second, then moved to the next item. This approach prevents overwhelming external APIs and helps avoid errors caused by too many requests at once.

Also, the Loop Over Items node is flexible—you can set batch sizes larger than one. For example, if scraping URLs, you might want to process ten URLs at a time, then wait before fetching the next batch. This is why the node is sometimes called the Split in Batches node.

Advanced Loop Settings: Error Handling and Workflow Stability

Looping can sometimes encounter errors. The Loop Over Items node has settings to help manage this. You can choose to continue on error or continue using an error output. The latter creates a separate error flow where you can handle errors differently.

Another useful setting is “Always Output Data.” When enabled, this prevents the workflow from stopping prematurely if the loop outputs no data. If unchecked, the workflow might finish unexpectedly, which can be confusing during troubleshooting.

Exploring Different Looping Scenarios with URLs

To clarify these looping behaviors, I used a sample list of URLs in an array. This array structure is similar to the task list example. I explored multiple scenarios:

  • Passing the array directly into a Code node: The node received one item containing the entire list of URLs. Adding a parameter to this item appended it at the end, rather than adding parameters to each URL individually.
  • Using Loop Over Items without splitting: Since the input was still one item (the whole array), the loop treated it as a single item, so adding parameters behaved the same as above.
  • Using a Split Out node before Loop Over Items: The array was split into individual URL items. Each then went through the loop and subsequent nodes separately. Adding parameters happened on each individual item, which is usually the desired behavior.

Split Out node creating individual URL items for looping

In this setup, each URL item passed through a Wait node and a Code node that added parameters. After processing, the results recombined into a list with parameters added to each URL separately.

Individual URL items processed and recombined after looping

Is the Loop Over Items Node Always Necessary?

Not always. If a node supports processing multiple items internally, you might not need an explicit loop. For example, the Code node can run once per item if you select the “Run Once for Each Item” mode. This lets you add parameters to each item without a Loop Over Items node.

Code node configured to run once for each item

However, some nodes only take the first item or don’t handle multiple items well. In those cases, you need the Loop Over Items node to split the data and process items one by one. When a node expects a single input and doesn’t support batch processing, looping is essential.

Code node set to run once for all items, processing only first item

Getting Comfortable with Looping and Data Items

Looping and handling multiple data items in n8n can feel tricky at first. I recommend experimenting with different scenarios to see how data flows through your nodes. Try using Split Out, Loop Over Items, and node settings for processing multiple items. This hands-on approach helps you learn when you need explicit looping and when n8n’s internal processing is enough.

Experimenting with different looping scenarios in n8n

Once you understand these concepts, you’ll build automations more efficiently and avoid common pitfalls like data dumping or workflow stopping unexpectedly. Mastering data flow and looping is a crucial step toward creating powerful workflows that handle complex data smoothly.

Leave a Comment