Global.set ARRAY[ ]

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

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

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

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

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 ${ }

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"));