[Javascript] dynamic var names
Mike Dougherty
mdougherty at pbp.com
Tue Aug 7 08:44:28 CDT 2007
On 8/7/07, Michael Borchers <list at tridemail.de> wrote:
> I dynamically create a name for a var, let's say
>
> var myDynVar = 'foo';
>
> Now I want to fill (var) foo with a value f.e. 'bar', so the next time I
>
> alert(foo) results in => bar;
>
> I tried several combinations with eval() but still didn't get it. Can anyone
> help?
Can you explain why you would ever need a variable with a dynamic name?
I understand using a hash:
var MyHash = {};
MyHash[key1] = "value1";
MyHash[key2] = "value2";
var lookup = MyHash[ lookupKey ];
More information about the Javascript
mailing list