Sun Chili!Soft ASP Sun Chili!Soft
ASP Sun Microsystems

 

JScript Enumerator Object

The Enumerator object provides a way to enumerate items in a collection.

Methods: JScript Enumerator Object

JScript Enumerator Object AtEnd Method

 

Returns a Boolean value indicating if an Enumerator object is at the end of a collection.

JScript Enumerator Object item Method

Returns the current item in the collection.

JScript Enumerator Object moveFirst Method

Resets the current item pointer to the first item in the collection.

JScript Enumerator Object moveNext Method

Moves the current item pointer to the next item in the collection.

Syntax: JScript Enumerator Object

new Enumerator(collection)

Arguments: JScript Enumerator Object

collection

Any collection object.

Remarks: JScript Enumerator Object

Collections differ from arrays in that the members of a collection are not directly accessible. Instead of using indices, as you would with arrays, you can only move the current item pointer to the first or next element of a collection.

The Enumerator object provides a way to access any member of a collection and behaves similarly to the for...in statement in JScript.

The following code shows the usage of the Enumerator object:

function ShowDriveList()

{

var fs, s, n, e, x;

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

e = new Enumerator(fs.Drives);

s = "";

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

{

x = e.item();

s = s + x.DriveLetter;

s += " - ";

if (x.DriveType == 3)

n = x.ShareName;

else if (x.IsReady)

n = x.VolumeName;

else

n = "[Drive not ready]";

s += n + "<br>";

}

Response.Write(s);

}

Copyright 2002 Sun Microsystems, Inc. All rights reserved. Legal Notice.