# Variables seem linked somehow

**URL:** <https://discourse.nodered.org/t/variables-seem-linked-somehow/81747>\
**Category:** General\
**Tags:** function-node\
**Created:** [3 October 2023 18:46 UTC](https://discourse.nodered.org/t/variables-seem-linked-somehow/81747 "2023-10-03T18:46:07Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 October 2023 10:34 UTC](https://discourse.nodered.org/t/variables-seem-linked-somehow/81747/5 "2023-10-04T10:34:44Z")

</div>

> [@BrallanH2](#):
>
> At this point, I'd like to understand what I did and am probably commonly doing wrong

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:

```auto
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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/a/6a5f3a9a1af6b58592bee897fda32f1a7f5b484b.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/e/de22a5a766c5f5398815f80ce4773993e44b0c5b.png)

---

_[View the full topic](https://discourse.nodered.org/t/variables-seem-linked-somehow/81747)._
