Connecting Tech Pros Worldwide Forums | Help | Site Map

Cast a string as an refernce to an object. Please HELP

news.west.cox.net
Guest
 
Posts: n/a
#1: Jul 23 '05
Hopefully this can be done and it is easy...

I have some object like

var a = new Object();
a.name = "Title";
a.vars = new Array(6);
a.vars[0] = "4";
a.vars[1] = "22";
etc...

for about 18 objects.

If I have a string like
var str = "a";

how can I reference object data, like str.vars[0]???

Thanks....



Mick White
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Cast a string as an refernce to an object. Please HELP


news.west.cox.net wrote:[color=blue]
> Hopefully this can be done and it is easy...
>
> I have some object like
>
> var a = new Object();
> a.name = "Title";
> a.vars = new Array(6);
> a.vars[0] = "4";
> a.vars[1] = "22";
> etc...
>
> for about 18 objects.
>
> If I have a string like
> var str = "a";
>
> how can I reference object data, like str.vars[0]???
>
> Thanks....
>
>[/color]
window[str].vars[0] or window["a"].vars[0]

If I have understood you correctly.
Mick


news.west.cox.net
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Cast a string as an refernce to an object. Please HELP


Thanks... works like a charm.

"Mick White" <mwhite13@rochester.rr.com> wrote in message
news:jaxmd.372$Uf.233@twister.nyroc.rr.com...[color=blue]
> news.west.cox.net wrote:[color=green]
>> Hopefully this can be done and it is easy...
>>
>> I have some object like
>>
>> var a = new Object();
>> a.name = "Title";
>> a.vars = new Array(6);
>> a.vars[0] = "4";
>> a.vars[1] = "22";
>> etc...
>>
>> for about 18 objects.
>>
>> If I have a string like
>> var str = "a";
>>
>> how can I reference object data, like str.vars[0]???
>>
>> Thanks....
>>
>>[/color]
> window[str].vars[0] or window["a"].vars[0]
>
> If I have understood you correctly.
> Mick
>
>[/color]


Closed Thread