Use value of variable as name in push operation

Is it possible, for the push operation, to use the value of a variable and not the name of the variable, as the attribute name in the object?

for (i=1; i<=5; i++)

This create the following objects in the msg.options:

msg.options : array[5]
0: object
i: 1
1: object
i: 2
2: object
i: 3
3: object
i: 4
4: object
i: 5

Here, it always pushes a new attribute "i", with the current value of "i".

But I don't want all objects to be called "i", I want them to be called as the value of the variable "i".

msg.options : array[5]
0: object
1: 1

Any ideas?

Hi @bjxevit

one small request - when sharing code snippets, please use the </> icon in the formatting toolbar to ensure they show up as proper code blocks.

You can do it with:

for (i=1; i<=5; i++) {
   var option = {};
   option[i] = i;

hey @knolleary,

thanks for the quick reply and the short info about sharing code.
Just started to participate in the forum.

That solution worked for me.