Function node - item.json.data not iterable, but it is

Hi!

I’m having a weird problem with the function node. It is receiving a json object that include an array of ids. I’m trying to iterate over them and log them to my console for debugging. Except its giving me an error (see below)

It says that Item.json.data is not iterable, except it is. As you can see in the screenshot, the javascript console also shows the output.

Here is the json object that it is using as input:

What am I doing wrong?

Cheers!

I assume that for some of the 407 items in total, that is not the case. According to the screenshot you did share, I assume the first item, where it is not iterable, is around index 25.

Hi Jan!

Thanks for the answer! I checked and you’re right, some don’t have an array. How can I check for this in the function script?

Cheers!

You can add an if around it: if (Array.isArray(item.json.data)) { ... }

1 Like

Thanks! Works like a charm :slight_smile:

1 Like

Great to hear! Have fun!