I am trying to understand the difference between $.each and ko.utils.arrayForEach, there is something more that a array iterations ?
I am using ko.utils.arrayForEach because I am working with knockout js but I just have curiosity.
ko.utils.arrayForEach
doesn't depend on jQuery and is simply a shortcut to writing something like:
for (var i = 0, j = myArray.length; i < j; i++) {
someMethod(myArray[i]);
}
It only works with arrays. jQuery is not a strict dependency of Knockout. If it is available, then there are a couple of places where Knockout will use it (string to DOM parsing and event handling).
$.each
requires jQuery (obviously) and is intended to be way more flexible. It can iterate over properties in an object as well as arrays and work with jQuery objects. It also gives you an index while you are looping.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With