Friday, April 17, 2015

Kendo arrayForEach vs Traditional jquery $.each loop

We have many options to run loop in javascript. But here if we compare the  ko.utils.arrayForEach and  Traditional jquery $.each loop.

Here are the reasons you can consider while selected between these two

1.  Traditional $.each loop is much faster than ko.utils.arrayForEach
2. Traditional $.each loop provides you the flexibility for Exit at any point of time while  ko.utils.arrayForEach doesn't support return


Example 

 ko.utils.arrayForEach(myCollection(), function (item) {
           if (!item.isAvailable)
                return false; // it will not work and the loop will run for whole collection

            });



$.each(myCollection(), function (index,item) {
           if (!item.isAvailable)
                return false; // it will work and it will quit from loop once the item is not available
         });

Post a Comment