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

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -