Variables seem linked somehow

In JavaScript (and many languages), objects (key-val objects/arrays/buffers/etc) are stored by reference. When you set global.somedata = msg.payload and flow.somedata = msg.payload you are storing a pointer to the original (singular) object. When you edit global.somedata you also edit flow.somedata

Bearing this in mind for the future will save you some troubles.

There are various ways to solve this. A function node can use:

global.set(ReadArray, RED.util.cloneMessage(msg.payload))
flow.set(DisplayArray, RED.util.cloneMessage(msg.payload))

You can branch flows and use a change node, much like you did.

image

2 Likes