Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use variable name stored in string ?

Status
Not open for further replies.

eequalsmc2plus1

Programmer
Aug 26, 2002
28
ZA
Hey,

Anyone know how to use a variable if its name is stored in another variable ?

eg:

var A="";
var B="";
var C="";

var X = new array(3);

X[1] = "A";
X[2] = "B";
X[3] = "C";

So now JUST using the variable X, I want to set the values of A B and C.

in other language i know you can say @X[1] = "whatever" and it will make A="whatever" but how u do it in JavaScript ?

Thanks
Damian


 
i'm not sure that you can. in this example:
[tt]
var a = "foo";
var A = [a];
A[0] = "bar";
alert(a);
alert(A[0]);
[/tt]
A[0] exists as a separate copy of a, not a reference to it. =========================================================
if (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top