Is an array as a payload not really an array?

My payload is an array:
Bildschirmfoto vom 2021-11-01 18-34-48


msg.payload.forEach((item) => {

gave me an error:
"TypeError: msg.payload.forEach is not a function"

So I used

Array(msg.payload).forEach((item) => {

and that worked.

But why didn't the first method?

Can you export and share that part of your flow with the sample data of msg.payload to demostrate the problem ?

Where has that value come from? It is possible its a non-Array type that looks enough like an Array for the sidebar to report it as such.

You could try adding a Function node with:

node.warn("Array.isArray: "+Array.isArray(msg.payload))
node.warn("typeof: "+(typeof msg.payload))
return msg

to get some more information on what the property actually is.

Wow, you guys are fast. And good call, it's not a true Array:

function : (warn)
"Array.isArray: false"
11/1/2021, 6:50:43 PMnode: 6ccdb2532bf27083function : (warn)
"typeof: object"

The payload came from a file through an xml and a few splits.

Thank you!

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