Access value of JavaScript variable by name?

Global variables are defined on the window object, so you can use:

var MyVariable = "Value of variable";
alert(window["MyVariable"]);

Leave a Comment