1. #1
    Sencha User
    Join Date
    Jan 2010
    Posts
    28
    Vote Rating
    0
    ladybug_3777 is on a distinguished road

      0  

    Default [Solved] for loop vs .each enumeration

    [Solved] for loop vs .each enumeration


    Wondering which is faster. Using "for" or ".each" to loop through items?

    Code:
    myFormCmp.items.each(function(comp) {//do stuff});
     
    VS
     
    for( var i = 0 ; i <  myFormCmp.items.length ; i++ ){
          var comp = myFormCmp.items.get(i);
          //do stuff
    }
    What is the best practice or does it all depend on what is happening within the loop?
    Last edited by ladybug_3777; 23 Apr 2010 at 9:31 AM. Reason: punctuation

  2. #2
    Sencha User fay's Avatar
    Join Date
    Apr 2007
    Location
    Ireland
    Posts
    1,750
    Vote Rating
    7
    fay will become famous soon enough fay will become famous soon enough

      0  

    Default


    If you look at the source code you'll see that, internally, each uses a for loop; it would be (slightly) faster for you to use "for", but not by a significant amount - it really depends on what you need to do. I use each because it makes my code easier to read!

  3. #3
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,251
    Vote Rating
    73
    Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold

      0  

    Default


    for-loops are faster, but require more lines to code.

  4. #4
    Sencha User
    Join Date
    Jan 2010
    Posts
    28
    Vote Rating
    0
    ladybug_3777 is on a distinguished road

      0  

    Default


    Thanks! Now how do I mark this thread as solved?

  5. #5
    Sencha User fay's Avatar
    Join Date
    Apr 2007
    Location
    Ireland
    Posts
    1,750
    Vote Rating
    7
    fay will become famous soon enough fay will become famous soon enough

      0  

    Default


    Now how do I mark this thread as solved?
    Edit your original post, click "Go Advanced", and add "[SOLVED]" to the post's Title.

Thread Participants: 2

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar