spacer
Yehuda Shiran October 28, 1999
Collections vs. Arrays
Tips: October 1999

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source
Internet Explorer's version of JavaScript, JScript, is very similar to the Microsoft's VBScript language. It includes many typical VB features, such as collections. In Visual Basic, the Collection object is an object-oriented version of the Visual Basic array. Collection objects, like arrays, are containers for data. Like the elements in arrays, the members of collections can be accessed by their index value or their key. Unlike Visual Basic, collections in JavaScript are zero-based. That is, the index of the first item in the collection is 0. The most well-known collection in JavaScript is document.all, supported by Internet Explorer 4.0x and above.

In JavaScript, collections don't have many advantages over arrays, because JavaScript is a loosely typed language. Given the similarity to arrays, why do we need collection objets? The major reason is ease of access and ease of maintenance:

  • Members can be retrieved based on either their key value of their index value. The item() method retrieves a member from the collection.
  • Members can be added before or after an existing member based on the laters index value. The add() method adds a member to the collection.
  • Members can be deleted based on their index value. Multiple deletions, however, should be done backwards, from higher index values to lower ones, since the collection is reindexed after each deletion. The remove() method deletes a member from the collection.
Now that you have an idea of what collections are all about, be sure to read more about Internet Explorer's implementation of this data type.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Administering RBAC in PHP 5 CMS Framework · xref: Automatic Cross Referencing Script · Book Review: Content Rich
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags