Forum Discussion

fayrehouse's avatar
fayrehouse
Frequent Contributor
12 years ago

foreach loops in JScript / C#Script...

Hi All, I have the following bit of C# sample code "lifted" from the net...sds foreach (Item myItem in findResults.Items) "findResults" is of type Microsoft.Exchange.WebServices.D...
  • Philip_Baird's avatar
    12 years ago
    Hi, Steve, JScript has no concept of a foreach loop such as that prescribed in C#, I would use the approach of an old school for loop




    for( var i = 0; i < findResults.Items.Count; i++ ) {


      myItem = findResults.Items[ i ];


      // Proces myItem...


    }



    The closest approximation to foreach is the for..in loop but this iterates over the properties of an object so can produce unexpected results and needs to be used carefully and with the hasOwnProperty() method as well as other safe guards