Permalink
Fetching contributors…
Cannot retrieve contributors at this time
102 lines (77 sloc) 3.17 KB
title ms.custom ms.date ms.prod ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic f1_keywords dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
Enumerator Object (JavaScript) | Microsoft Docs
01/18/2017
windows-client-threshold
devlang-javascript
language-reference
Enumerator
JavaScript
TypeScript
DHTML
Enumerator object
63f03c21-d58c-47db-a728-4d8d88b0a422
21
mikejo5000
mikejo
ghogen

Enumerator Object (JavaScript)

Enables enumeration of items in a collection.

[!WARNING] This object is supported in Internet Explorer only, not in [!INCLUDEwin8_appname_long] apps.

Syntax

  
enumObj = new Enumerator([collection])   

Parameters

enumObj
Required. The variable name to which the Enumerator object is assigned.

collection
Optional. Any Collection object.

Remarks

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 move the current item pointer only 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.

Example

The following code shows the usage of the Enumerator object:

var bytesPerGB = 1024 * 1024 * 1024;  
  
var fso = new ActiveXObject("Scripting.FileSystemObject");  
  
document.write(fso.Drives);  
var e = new Enumerator(fso.Drives);  
  
var driveString = "";  
  
e.moveFirst();  
while (e.atEnd() == false)  
{  
    var drv = e.item();  
  
    driveString += drv.Path + " - ";  
  
    if (drv.IsReady){  
        var freeGB = drv.FreeSpace / bytesPerGB;  
        var totalGB = drv.TotalSize / bytesPerGB;  
  
        driveString += freeGB.toFixed(3) + " GB free of ";  
        driveString += totalGB.toFixed(3) + " GB";  
    }  
    else{  
        driveString += "Not Ready";  
    }  
  
    driveString += "<br />";;  
  
    e.moveNext();  
}  
document.write(driveString);  
  
// Output: <drive information  
  

Properties

The Enumerator object has no properties.

Methods

atEnd Method | item Method | moveFirst Method | moveNext Method

Requirements

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, and Internet Explorer 10 standards. Not supported in [!INCLUDEwin8_appname_long] apps. See Version Information.

See Also

Boolean Object