javascript - ["var"+1]=someValue - Can something like this be done? -
function givevalue(n){ ["r"+n]=5; } givevalue(10); you idea.
the point have handful of variables similar name, varying in number @ end. using switch statement fine few variables few times, particular project driving me crazy. know can do:
var r2="lol"; var somevar=eval("r"+2); //somevar=="lol" and wondering if can dynamic reference left of assignment.
is possible?
if really want that, should work:
function givevalue(n){ window['r'+n] = 5; } givevalue(10); console.log(r10) but please, don't it!
you should use arrays!
Comments
Post a Comment