JavaScript tutorial:
moveFirst method

 

Applies to: Enumerator Object

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

Syntax

myEnum.moveFirst( )

The myEnum argument is any Enumerator object.

Example

If there are no items in the collection, the current item is set to undefined.

In following example, the moveFirst method is used to begin evaluating members of the Drives collection from the beginning of the list:

<HTML>
<HEAD>
<SCRIPT LANGUAGE= JavaScript>
function ShowFirstAvailableDrive()
{
var fso, s, e, x;
fso = new ActiveXObject("Scripting.FileSystemObject");
e = new Enumerator(fso.Drives);
e.moveFirst();
s = "";
do
{
x = e.item();
if (x.IsReady)
{
s = x.DriveLetter + ":";
break;
}
else
if (e.atEnd())
{
s = "No drives are available";
break;
}
e.moveNext();
}
while (!e.atEnd());
return(s);
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT LANGUAGE= JavaScript>
document.write(ShowFirstAvailableDrive());
</SCRIPT>
</BODY>
</HTML>

To run the code above, paste it into JavaScript Editor, and click the Execute butto

See also: atEnd Method, item Method, moveNext Method