Why the Set node returns a length of an array instead of the array itself?

Hello friends!
I have this code in an expression in the Set node.

$node["Item Lists"].json["pledge"]["isRecurrent"] === 'false'
? $json["fields"]["Seznamy kontaktů"].push('recx2v1IUczJc7Fsv') 
: $json["fields"]["Seznamy kontaktů"].push('recdzgujTppgs1vrE')

The Set node returns a length of the array instead of the array itself. Also, the number is increasing when interacting with the workflow. The original array has two items, I am adding a third one – the length is 88 and increasing.

Can you please suggest how to resolve this?
Thank you.

Has actually nothing to do with how n8n works, but rather how JavaScript works and what push returns (which is the new length of the array it pushed to):

Here an example:
Screenshot from 2022-12-17 11-02-52

Here are the docs of push:

Hi @jan – I was so sure this method returns the array, so I even did not check the docs. This is stupid, sorry and thanks!

Ah and regarding the second part. How to do it. Normally you could do something like this:

[...$json["fields"]["Seznamy kontaktů"], 'recx2v1IUczJc7Fsv']

but honestly do not know right now why it does not work in n8n.

In this case probably best to use a Code-Node.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.