473,405 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

arrayname.length ==> alternative??

Hi,

Array('s) like:
customer[1]="John Doe";
items[1][34]="abc";
items[1][422]="aadsfasdf";
customer[2]="Pietje Puk";
items[2][3545]="asdfasdfasdf";
items[2][133]="asdfasdf";
items[2][1155]="sdkk;lj,8i";
etc..

Now: items[2].length is _not_ returning 3 (or 2 whatever point of view :-)..
Any alternative for:
for(anItem in items[2]) { count++; }

??
Thanx in advance,
Marco Snoek
Jul 23 '05 #1
2 1817
On Sun, 19 Sep 2004 08:45:54 +0200, wrote:

[snip]
customer[2]="Pietje Puk";
items[2][3545]="asdfasdfasdf";
items[2][133]="asdfasdf";
items[2][1155]="sdkk;lj,8i";
etc..

Now: items[2].length is _not_ returning 3 (or 2 whatever point of view
:-)..
No, it won't. Arrays in ECMAScript are sparse arrays: all elements that
aren't explicitly defined between two indicies are given the value,
undefined. So, if you wrote:

var a = [];
a[100] = 'a value';

there would be one explicitly defined value at index 100, and 100
undefined elements before it giving a length of 101.
Any alternative for:
for(anItem in items[2]) { count++; }


The for..in statement seems to be the only way to move through the defined
elements.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
"Marco Snoek" <_[mps]@[webmind.nl]_Dont_you_dare_send.spam> writes:
....
items[2][3545]="asdfasdfasdf";
items[2][133]="asdfasdf";
items[2][1155]="sdkk;lj,8i";
etc..

Now: items[2].length is _not_ returning 3 (or 2 whatever point of view :-)..
No, it gives 3546, one larger than the largest index of an element of
the array.
Any alternative for:
for(anItem in items[2]) { count++; }


No, short of keeping track of how many entries have been assigned
yourself.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: James | last post by:
I am currently working on a PHP based website that needs to be able to draw from Oracle, MS SQL Server, MySQL and given time and demand other RDBMS. I took a lot of time and care creating a...
5
by: john | last post by:
Hi I am devlopeing a data centric intranetsite with data in mysql database I would like your opinion on this architecture Data will be fetched from database by python & converted into xml The...
129
by: Torbjørn Pettersen | last post by:
I've started cleaning up my HTML and implementing CSS. So far I've used FrontPage, but am switching over to DreamWeaver. Reading a bit on W3Schools.com and W3.org I see there are a lot of HTML...
34
by: Mark Moore | last post by:
It looks like there's a pretty serious CSS bug in IE6 (v6.0.2800.1106). The HTML below is validated STRICT HTML 4.01 and renders as I would expect in Opera, FrontPage, and Netscape. For some...
44
by: Jim M | last post by:
I have had great success with using <iframe> with overflow-y set to auto. I can get a similar look with the <iframe> tag. BUT... In all cases I need to have fixed heights. Is there a way to...
14
by: Steven T. Hatton | last post by:
I find writing things such as (*ptr)(arg), and (*ptr), to be at least awkward. I've often thought the following would be useful as an alternative form of ptr->operator(arg), ptr->operator: ...
5
by: Mark Preston | last post by:
Admission first - I don't actually have a problem here but have noticed that a lot of people have been asking similar questions and getting very varied answers. What I've done is to sort of...
3
by: kimi | last post by:
Hello, yes i try to learn c-programming.So i have a question on my code, but if i am wrong here please tell me a group where i belong to. I wrote a function which fgets a filename from the...
0
by: davidb | last post by:
Hi, does someone know how to get the length of a 2 dimensional string array: here what i need: ---------------------------------------------------------------- char **getList(void){ char...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.