$.each and forEach take their arguments in opposite orders

$.each hands the callback the index first and the value second. Array.prototype.forEach hands it the value first and the index second. Both signatures are two arguments of convenient types, so getting them the wrong way round produces no error at all — just a total that is the sum of the row numbers.

$.each(orders, function (index, order) { /* ... */ });
orders.forEach(function (order, index) { /* ... */ });

// and jQuery's own map does not agree with jQuery's own each
$.map(orders, function (order, index) { return order.total; });
orders.map(function (order, index)    { return order.total; });

$.each is the older signature and it is consistent with $.fn.each, where the index genuinely does come first because the value is also this. $.map was written later to match the native map instead, so the two jQuery functions disagree with each other — which is what catches people who learned the rule as “jQuery puts the index first”. The reason to keep reaching for $.each at all is that it also walks plain objects, where the first argument is the key. For an array on any browser still supported, forEach is native, faster, and readable without knowing which library is loaded. Where the two are interchangeable, picking one per file is worth more than picking the right one.