There are already a few other posts on SO for this topic, like: Loop through array and return sum of all values. I have used the techniques from there and am still not getting the right result.
I have a UL with Several LI's in it. Each of those LI's has text in them which I need adding to an array, once they have all been added I need to add them up.
JSFIDDLE: http://jsfiddle.net/4Be6N/
Here is the jQuery:
$(document).ready(function() {
var arrTotals = [];
var totalAmount = 0;
$( ".cartprice" ).each(function( index ) {
arrTotals.push = $(this).text();
console.log(arrTotals);
});
for (var i = 0; i < arrTotals.length; i++) {
totalAmount += arrTotals[i] << 0;
}
console.log('Total Amount: ' + totalAmount)
});
However, the console is displaying:
Total Amount: 0
Can anyone see why?