Benefits of ko.utils.arrayForEach (and tapping into its increment)?

1,395 views
Skip to first unread message

Benjamin Allison

unread,
Apr 11, 2012, 9:21:33 PM4/11/12
to knock...@googlegroups.com
Just wondering what the benefits of the ko.utils.arrayForEach are, compared to just looping with plain old JS.

One thing about using JS's for is that by nature of it's declaration, it includes an increment. Does arrayForEach have some internal increment that I don't know about? Or do I just need to declare my own variable outside and increment it manually?

rpn

unread,
Apr 11, 2012, 11:23:55 PM4/11/12
to knock...@googlegroups.com
ko.utils.arrayForEach just uses a less verbose and easier syntax.  It does not provide an index.

If you are really doing a lot of looping and/or potentially looping over many items, then an actual for loop will perform slightly better (I have seen some measurements show 8x better performance in some cases) based on avoiding the overhead of the extra function call.  In the majority of cases though, the difference won't have a major impact.
Reply all
Reply to author
Forward
0 new messages