...

View Full Version : problem with logic keys



stack13
03-13-2005, 10:39 PM
Hi. Have some troubles checking arrays length:



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 ...


alert (holder[i]["ID"]);

... can see its value normally.
What am I doing wrong?

codegoboom
03-14-2005, 02:22 AM
It looks like the array's length is 0, so... (properties are not array members, btw).

stack13
03-14-2005, 03:22 AM
Right. Length is 0. Array items have no properties. So, how do I loop them through?

codegoboom
03-14-2005, 03:26 AM
Use a 'for... in...' loop.

stack13
03-14-2005, 03:53 AM
Ok folks. The reason why I could not get through members is at the for statement. I should have used:


for (var i =0;i < holder.length;i++) {
h = holder[i];
for (var k in h) {
alert (h[k]);
}
}

:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum