Page 1 of 1

Instantiate a variable whose name is the value of another

Posted: Wed Aug 02, 2006 4:01 pm
by kendall
Can u create a variable whose name is the value of another in JS?

e.g.

Code: Select all

var variable1 = "myName";
// create the var named myName;
eval(variable) = 2 //...?
P.S. what is the tag used to highlight this as a javascript code?

Kendall

Posted: Wed Aug 02, 2006 4:52 pm
by feyd

Code: Select all

var varname = 'someThing';
eval(varname + ' = 2;');
I believe.. I avoid eval() at all costs.

Code: Select all

..