Implementing For Each in JScript

24 Apr 2007 11:01
function forEach(enumerable, delegate)
{
    for (var enumerator = new Enumerator(enumerable); !enumerator.atEnd(); enumerator.moveNext())
    {
        delegate(enumerator.item());
    }
}

Used like this:

forEach(employees,
        function(employee)
        {
            WScript.Echo(employee.Salary);
        });