Closed Thread Icon

Preserved Topic: JavaScript Array Length detection (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=18441" title="Pages that link to Preserved Topic: JavaScript Array Length detection (Page 1 of 1)" rel="nofollow" >Preserved Topic: JavaScript Array Length detection <span class="small">(Page 1 of 1)</span>\

 
PaulSmith
Bipolar (III) Inmate

From: Manchester
Insane since: Jun 2001

posted posted 05-09-2002 20:14

Hello,

I am trying to detect if an Array has exceeded 4 elements and if so to produce a document.write else to do nothing.

Life in the Bus Lane : Weblog

dk01
Bipolar (III) Inmate

From: dk's house of love
Insane since: Oct 2001

posted posted 05-09-2002 20:25
code:
if(myarray.length > 4)
{
document.write("The array is too long");
}



-dk

- can't decide? have another drink.

PaulSmith
Bipolar (III) Inmate

From: Manchester
Insane since: Jun 2001

posted posted 05-09-2002 22:45

I know I have tried that, but it does not return the correct array length. It is probably something I am doing wrong. The array I am reading the length from is added to by a for loop but I am pretty sure that it is not in-accurate.

Life in the Bus Lane : Weblog

Veneficuz
Paranoid (IV) Inmate

From: A graveyard of dreams
Insane since: Mar 2001

posted posted 05-09-2002 22:49

Would be easier if you gave us a link to were the problem is

But the problem might be that the array.length method returns the number of entries, so if you have an array of array[0] to array[3] it would return the length 4 (0,1,2,3 -> 4). So it might help if you exchange 4 in dk01's snippet with a 3. Hope that helps...


-= Veneficuz =-
"Mundus vult decipi. Ergo decipiatur."

PaulSmith
Bipolar (III) Inmate

From: Manchester
Insane since: Jun 2001

posted posted 05-10-2002 17:18

I have figured it out now. I was being soo stupid. The array I was reading from got added to by a function which took the element number from the onClick event. So for example if the element number assigned to the particular onClick event was 23 then it made the array length 23! So even though I had only added 4 peices of data it made the array length 23. :-)

I am such a dumbass sometimes, I had been coding for a few hours when I hit that problem and couldn't see the wood for the trees. (if you undertand that very north english expression)

Life in the Bus Lane : Weblog

« BackwardsOnwards »

Show Forum Drop Down Menu