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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

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.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint