How to dynamically generate variables in JavaScript? -


my goal dynamically generate variables foo1, foo2 , foo3 , assign bar them using following code:

for (var i=1;i<=3;i++) {     myapp.set({ foo+i: "bar" }) } 

i tried using eval on foo doesn't work. ideas?

for (var i=1;i<=3;i++) {     var myobj = {};     myobj['foo' + i] = 'bar';      myapp.set(myobj); } 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -