How can i use xyz to name a variable?
I am trying something like this:
var xyz = "test";
var (xyz) = "abc";
alert (test);
Would have to display an alert "abc"
Printable View
How can i use xyz to name a variable?
I am trying something like this:
var xyz = "test";
var (xyz) = "abc";
alert (test);
Would have to display an alert "abc"
You usually aren't supposed to use eval(), but here is one way:
var xyz = "test";
eval("var " + xyz + " = 'abc';");
alert (test);
there's almost always a better option than eval()
is this what you are talking about?
(creates "test" as a global, ie, window variable)Code:var xyz = "test";
window[xyz] = "abc";
alert (test);