# Adding data to a static flow variable Array?

**URL:** https://discourse.nodered.org/t/adding-data-to-a-static-flow-variable-array/6856
**Category:** General
**Created:** [15 January 2019 18:36 UTC](https://discourse.nodered.org/t/adding-data-to-a-static-flow-variable-array/6856 "2019-01-15T18:36:19Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![tcontrada](https://avatars.discourse-cdn.com/v4/letter/t/f1d935/32.png) [@tcontrada](https://discourse.nodered.org/u/tcontrada)
#### Post date: [15 January 2019 18:36 UTC](https://discourse.nodered.org/t/adding-data-to-a-static-flow-variable-array/6856/1 "2019-01-15T18:36:19Z")

</div>

Here is my code snippet for initializing my flow variable:

var a = new Array(65);  
flow.set("myArray",a);

In a Function Node I want to add the msg.payload to the myArray flow variable until I fill up the array.  
How do I write the correct syntax to add it to the Flow variable?

Something like flow.set.push("myArray",msg.payload); ?????

Thanks...

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [15 January 2019 19:19 UTC](https://discourse.nodered.org/t/adding-data-to-a-static-flow-variable-array/6856/2 "2019-01-15T19:19:38Z")

</div>

Firstly it is generally recommented to use  
`var a = [35];`  
rather than using `new Array`. Which is easily misunderstood. For example  
`new Array(35,60);`  
may not do what you expect. The simplest way to add a new element is probably

```auto
a = flow.get("myArray");
a.push(msg.payload);
flow.set("myArray", a);

```

If you really want to get it in one statement then  
`flow.set("myArray", flow.get("myArray").push(msg.payload));`

---

<div class="post-metadata">

### Author: ![tcontrada](https://avatars.discourse-cdn.com/v4/letter/t/f1d935/32.png) [@tcontrada](https://discourse.nodered.org/u/tcontrada)
#### Post date: [16 January 2019 22:00 UTC](https://discourse.nodered.org/t/adding-data-to-a-static-flow-variable-array/6856/3 "2019-01-16T22:00:08Z")

</div>

Thanks, works fine!

---

<div class="post-metadata">

### Author: ![dflvunoooooo](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@dflvunoooooo](https://discourse.nodered.org/u/dflvunoooooo)
#### Post date: [13 October 2020 21:20 UTC](https://discourse.nodered.org/t/adding-data-to-a-static-flow-variable-array/6856/4 "2020-10-13T21:20:53Z")

</div>

I just had the same problem. Thanks for the solution @Colin.

But for me only the first solution worked, the

```auto
flow.set("myArray", flow.get("myArray").push(msg.payload));

```

would somehow destroy the array.

Edit1: Funny, but

```auto
flow.set("myArray", flow.get("myArray")+1);

```

does work.
