Return function response as multiple items

Hi,
I have a question about how to return multiple items after a function node.
I have 2 arrays in input and I made a filter with an include so in return I have an array with the values I’m looking for.
I just want to return this array as multiple items for the next node and I’ve seen as in this thread that some code like this with my one dimension array would work :

const newItems = [];

for (const item of myArray) {
  newItems.push({json: item});
}

return newItems;

but I have an error :

ERROR: The json-property has to be an object! [Line 109]

Here is my output with just the array in Json:


It’s fine but I wanted to have 3 elements on my next input node to be run 3 times

Please share the workflow

If you could help me, thank you.

Hello,

This is because you return an object instead of an array.

Here is the code I used:

var labelCategories = ["ClientPremium", "Relance", "AnnulationCommande"];

const newItems = labelCategories.map(el => ({json: {label: el}}));

return newItems;

And here is the workflow:

Hope it helps!!

Thank you very much for your help, it works well