I need to create a variable from the value of another variable. As an example, this would be similar to how I would do this in VFP:
nameOfNextVar = "port_no_1";
eval(nameOfNextVar) = 7493
Then I will be able to say:
alert(port_no_1);
And the alert would give me 7493…
Is this possible in JavaScript???
TIA
Dennis
You can try something like this using JavaScript
evalmethod. But usingevalshould be avoid if possible.http://jsfiddle.net/ngTQf/
Other alternative is to define properties on the object or a current instance. You can also use
windowto define variables or properties.http://jsfiddle.net/ngTQf/2/