# Global.set ARRAY\[ \]

**URL:** <https://discourse.nodered.org/t/global-set-array/3193>\
**Category:** General\
**Created:** [16 September 2018 21:23 UTC](https://discourse.nodered.org/t/global-set-array/3193 "2018-09-16T21:23:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sweetwater](https://avatars.discourse-cdn.com/v4/letter/s/d07c76/32.png) [@sweetwater](https://discourse.nodered.org/u/sweetwater)\
**Post date:** [16 September 2018 21:23 UTC](https://discourse.nodered.org/t/global-set-array/3193/1 "2018-09-16T21:23:34Z")

</div>

We have declared a Global Array MyStatus and initialized it with array [1,2,3,4,5]  
var MyStatus = global.set[1,2,3,4,5];

Example 1 'hardcoded' so the DataUpdate is stored in the 4th Array position '3'. THIS is OK  
[//global.set](https://global.set)("MyStatus['3']",global.get("DataUpdate"));

Example 2 We then replaced '3' with a variable.  
var RXSelected = 3;

1. [//global.set](https://global.set)("MyStatus['RXSelected']",global.get("DataUpdate"));

But the 2nd example does not write in the DataUpdate into the array at all.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [16 September 2018 22:04 UTC](https://discourse.nodered.org/t/global-set-array/3193/2 "2018-09-16T22:04:55Z")

</div>

Hi @sweetwater

In your 2nd example, the key you are using is the literal string `"MyStatus['RXSelected']"`. JavaScript doesn't know you want part of that String to be replaced by the value of a variable.

You have to build the string up:

```
global.set("MyStatus["+RXSelected+"]", global.get("DataUpdate"));

```

Or, you can use a string template:

```
global.set(`MyStatus[${RXSelected}]`, global.get("DataUpdate"));

```

Note in this second example the string is surrounded by a single backtick (`) and the local variable you want to insert is surrounded by `${ }`

---

<div class="post-metadata">

**Author:** ![sweetwater](https://avatars.discourse-cdn.com/v4/letter/s/d07c76/32.png) [@sweetwater](https://discourse.nodered.org/u/sweetwater)\
**Post date:** [17 September 2018 12:21 UTC](https://discourse.nodered.org/t/global-set-array/3193/3 "2018-09-17T12:21:49Z")

</div>

Thank you Nick.  
Oops. Makes total sense.  
Your inputs are clear and 100% correct. We concatenated the Strings with the variable and of course it works as expected.  
global.set("MyStatus["+RXSelected+"]", global.get("DataUpdate"));
