Use dynamic variable names in JavaScript
问题 In PHP you can do amazing/horrendous things like this: $a = 1; $b = 2; $c = 3; $name = \'a\'; echo $$name; // prints 1 Is there any way of doing something like this with Javascript? E.g. if I have a var name = \'the name of the variable\'; can I get a reference to the variable with name name ? 回答1: Since ECMA-/Javascript is all about Objects and Contexts (which, are also somekind of Object), every variable is stored in a such called Variable- (or in case of a Function, Activation Object ). So