[Javascript] Array-Indexing Problem

Tim Makins spindrift at oceanfree.net
Mon Sep 13 05:41:27 CDT 2004


Yes, that works too. Many thanks for the speedy reply also, Laurent. I must
learn some more about what is going on here - for some reason I keep making
this mistake.

Tim in Ireland.

----- Original Message ----- 
From: "Laurent Muchacho" <LaurentM at london.virgin.net>
To: "'[JavaScript List]'" <javascript at LaTech.edu>
Sent: Monday, September 13, 2004 11:31 AM
Subject: RE: [Javascript] Array-Indexing Problem


> Hi Tim,
>
> Try this and it work fine
>
> var alias = eval('viewlist'+ index_num);
>
> Mainly when you do the first alert alias is a string and it will still be
> evaluated as a string on the third alert
> but by putting your string into an eval() you will then have the object.
>
> Laurent
>
> -----Original Message-----
> From: Tim Makins [mailto:spindrift at oceanfree.net]
> Sent: 13 September 2004 11:26
> To: [JavaScript List]
> Subject: [Javascript] Array-Indexing Problem
>
>
> Hi - please can you have a look at the script below. The first and second
> Alerts work OK, but the third one fails. Why is that, and how can I
correct
> it ?
>
> Tim in Ireland.
>
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <html><head>
> <meta content="text/html; charset=windows-1252" http-equiv=Content-Type>
> <script language="javascript">
> viewlist1 = {
> colname: ["John","Frank","George"],
> colwidth: [200,50,150]
> }
>
> viewlist2 = {
> colname: ["Jane","Margaret","Sue"],
> colwidth: [89,33,264]
> }
>
> viewlist3 = {
> colname: ["Apple","Pear","Banana"],
> colwidth: [12,4435,22]
> }
> </script>
> </head>
> <body>
> <script language="javascript">
> var index_num = 2;
> var alias = 'viewlist'+ index_num;
> alert(alias);
> alert(viewlist2.colname[0]);
> alert(alias.colname[0]);
> </script>
> </body>
> </html>
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
>
> This E-mail and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they are
addressed.  If you have received this E-mail in error please notify the
system manager.  This message contains confidential information and is
intended only for the individual named.  If you are not the named addressee
you should not disseminate, distribute or copy this E-mail.
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>




More information about the Javascript mailing list