Enumerator object (Object/JScript)

A special object supported by MSIE for processing collections of objects.

Availability:

JScript - 3.0
Internet Explorer - 4.0
JavaScript syntax:IEmyEnumerator = Enumerator
IEmyEnumerator = new Enumerator(aCollection)
Argument list:aCollectionThe collection to be enumerated
Object properties:constructor
Object methods:atEnd(), item(), moveFirst(), moveNext()

An Enumerator object provides a way to enumerate through all the objects in a collection (aka Array). You can create a new Enumerator, giving it your collection as an argument and can then access the items in the collection in a more sophisticated way than simply using a for loop.

You can use the enumerator to cycle through the items in a collection in much the same way as a for( ... in ... ) loop would enumerate the properties. However, in some collections, objects have more than one entry. They may have an indexed entry and an associative entry. An enumerator should traverse the collection visiting each item only once. A for loop may visit objects several times.

The available set of methods and properties is somewhat limited compared with enumerator objects in other languages.

Because this is only available on MSIE and is severely dysfunctional on the Macintosh version of MSIE 5, its use is somewhat limited from the portability point of view. It is recommended that you avoid using it for the time being. Later, when it is more widely and reliably available, it may be more useful.

Do not confuse DOM NodeList arrays with Enumerator or Collection objects. The NodeListitem() method is subtly different to the Enumerator.Item() method.

Warnings:

Example code:

   // Instantiate a file system object

   myFileSystem = new ActiveXObject("Scripting.FileSystemObject");

   // Create an enumerator

   myEnum = new Enumerator(myFileSystem.Drives);

   // Traverse the Drives collection via the enumerator

   for(; !myEnum.atEnd(); myEnum.moveNext())

   {

   processDrive(myEnum.item());

   }

   // A function to do something with each disk drive

   function processDrive(aDrive)

   {

   ...

   }

See also:Collection object, Files object, NodeList object

PropertyJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
constructor n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning

MethodJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
atEnd() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
item() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
moveFirst() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
moveNext() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-