Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-13-2005, 09:39 PM   PM User | #1
stack13
New to the CF scene

 
Join Date: Mar 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
stack13 is an unknown quantity at this point
problem with logic keys

Hi. Have some troubles checking arrays length:
Code:
var holder = column = new Array ();
column[0] = new Array ();
column[0]["ID"] = 1;
column[0]["TITLE"] = "Revistas";
column[0]["DESCRIPTION"] = "Revistas Viejas";
column[0]["PUBLICATION_DATE_DAY"] = 1;
column[0]["PUBLICATION_DATE_MONTH"] = 1;
...

    for (var i=0; i < holder.length;i++) {
        if (holder[i].length) alert ("Voila!");
        ...
    }
The fact is I cant get into holder inner arrays by referring its logic key. However, if I call ...
Code:
alert (holder[i]["ID"]);
... can see its value normally.
What am I doing wrong?
stack13 is offline   Reply With Quote
Old 03-14-2005, 01:22 AM   PM User | #2
codegoboom
Regular Coder

 
Join Date: Aug 2004
Location: codegoboom@yahoo.com
Posts: 999
Thanks: 0
Thanked 0 Times in 0 Posts
codegoboom is an unknown quantity at this point
It looks like the array's length is 0, so... (properties are not array members, btw).
__________________
*this message will self destruct in n-seconds*

Last edited by codegoboom; 03-14-2005 at 01:33 AM.. Reason: 'members' meaning 'items'...
codegoboom is offline   Reply With Quote
Old 03-14-2005, 02:22 AM   PM User | #3
stack13
New to the CF scene

 
Join Date: Mar 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
stack13 is an unknown quantity at this point
Right. Length is 0. Array items have no properties. So, how do I loop them through?

Last edited by stack13; 03-14-2005 at 02:25 AM..
stack13 is offline   Reply With Quote
Old 03-14-2005, 02:26 AM   PM User | #4
codegoboom
Regular Coder

 
Join Date: Aug 2004
Location: codegoboom@yahoo.com
Posts: 999
Thanks: 0
Thanked 0 Times in 0 Posts
codegoboom is an unknown quantity at this point
Use a 'for... in...' loop.
__________________
*this message will self destruct in n-seconds*
codegoboom is offline   Reply With Quote
Old 03-14-2005, 02:53 AM   PM User | #5
stack13
New to the CF scene

 
Join Date: Mar 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
stack13 is an unknown quantity at this point
Ok folks. The reason why I could not get through members is at the for statement. I should have used:
Code:
    for (var i =0;i < holder.length;i++) {
        h = holder[i];
        for (var k in h) {
            alert (h[k]);
        }
    }
stack13 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:53 AM.


Advertisement
Log in to turn off these ads.