I am batching requests to an API which returns a field containing array. I’m using split-out to parse out array and append to an existing variable. However, I am getting an odd result that seems to create an array of arrays. I was able to find a workaround with the Code node, but the behavior from split-out to set node seems odd. Ideally I want to avoid using Code node as I read that it is a memory intensive node.
Hey @jtoh , you have different datasets produced by Split Out node and Code nodes. You cannot expect the same result if your data input is different.
If you want the result as in Code node then you do not need Split Out node as its role is to take the items out of an array (which is not what you do in Code node).
Yes, so I tried using the Set node alone. But I could not figure out why it wasn’t appending to the existing array. Here is the updated workflow to demonstrate.
Because with each loop you run a different iteration independent of the previous one. If you want to refer to a previous iteration you need to engage $runIndex variable. See Output of other nodes | n8n Docs.
then this means, by the 2nd iteration, final_results should already contain the previous $json.data. This should just append the new $json.data to it shouldn’t it?
I don’t understand where $runIndex would be applicable here since that doc shows it applies to all, first and last methods, which i’m not using.
Hey @jtoh , I think I misunderstood. The problem with your append is you are appending arrays to the array in “Create vars”. I believe you want to append items (not array of items) to the array. For that, you need to replace append with concat as below:
Yup, its funny I actually realized that too. But unfortunately, the behavior is still the same. I pinned the data for you to see. It must be something up with that set node because i’m seeing the correct data from the input window.