Reference variable name in a loop

Good evening

I have a function looking at a string of 6 characters, my function uses a loop to look at each character in turn and if the value matches a temp value a event occurs.

I have at the beginning of the function

var temp1 = some value
var temp2 = some value


if my logic is true then I want to do the following where x is the array position (1-6)

temp + x = context.get('T1'); this fails

if its static

temp1 = context.get('T1'); it works

Many thanks

What is temp?

It would probably be best to show us your function as it isn't at all clear what you are trying to do. Copy/paste the code here and use the </> button at the top of the forum entry window to paste it in.

Not sure what you are trying to achieve there? That isn't valid JavaScript.

You could set an array entry for each temp.
temp[x] = context.get('T1');
assuming x is a number that increments.
Best to declare temp earlier in your code.
let temp = [];
access temp[0] etc

Many thanks for that it is just what I was looking for, so glad you understood my convoluted question.