JavaScript tutorial:
Enumerator object

 

Methods

Properties

The Enumerator object is use to enables enumeration of items in a collection.

Syntax

new Enumerator(collection)

The collection argument is any collection object.

Example

Collections differ from arrays in that the members of a collection are not directly accessible. Instead of using indexes, 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...Each statement in VBScript.

The following code shows the usage of the Enumerator object:

<HTML>
<HEAD>
<SCRIPT LANGUAGE= JavaScript>
function ShowDriveList()
{
var fso, s, n, e, x;
fso = new ActiveXObject("Scripting.FileSystemObject");
e = new Enumerator(fso.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>";
}
return(s);
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT LANGUAGE=JavaScript>
document.write(ShowDriveList());
</SCRIPT>
</BODY>
</HTML>

  To run the code above, paste it into JavaScript Editor, and go to View, Internal Page Viewer or press F5.