Function with loop array

Hi there,
I am trying to do a loop using an array, but I don’t know how to do it.
Can someone give me some tips?

As long as the function node returns the array in the right format, n8n will automatically iterate over all inputs. Check the example below.

Hi @RicardoE105, first of all, thank you for your prompt answer.
Your solution is good, however, I’d like to do something like for each position on the array a loop, for instance, if the array has 5 positions, then the loop should occur 5 times and thus perform the validations of both IFs.

Hey @tuliovargas,

Doesn’t the example that Ricardo shared, solve the issue? You don’t have to create a loop. Almost all the nodes in n8n iterate over all incoming items. If you execute the example workflow, you will observe that both the IF nodes process all the incoming data.
You can learn more about looping in n8n in the docs here: Looping in n8n | Docs

If I missed something, or if anything is not clear, please let us know :slight_smile:

Hi @harshil1712 and @RicardoE105 ,
Can you see it:

  • If validation is not working, it should be looping only the array’s positions;
  • How to for each execution just show the position “i” of the array?

Hey @tuliovargas,

To make sure that I understood it correctly, you want to use the condition on the item’s position and not the item itself, right?

For example, if the array is [1, 4, 53, 34], you want to check for the position (eg. 2) and not the element itself. Is that right?