How to dynamically generate variables in JavaScript? -
this question has answer here:
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
Post a Comment