[Javascript] variable whose name is the result of a calculation?

Anthony Webster awebster at venda.com
Wed Dec 11 05:50:52 CST 2002


hi all,

I want to define a new variable, whose name is the result of a calculation.

does this make sense? a simple example follows

var1 = 'ora';
var2= 'nge';
var3 = var1 + var2;
// result:
// var3 = 'orange';
eval(var3) = '263';
// intended result:
// orange = '#FB8E36';

of course when I do this, javascript is not happy. it doesnt like the left hand side with the 'intended result' bit.

why am I doing things like this? I am going to be supplied the names of the colours without knowing what they will be. I will need to evaluate what they are and then declare variables for each of them so I can reuse this information.

any help would be greatly appreciated!

thanks,

anthony



More information about the Javascript mailing list