I have a cart array with items that I'm counting like this:
cart.length
The problem is, if one item has 6 quantity and the other has 1 quantity, it shows only 2 instead of 7. How do I count the total of the items? The structure is like this:
I've tried a million things and none of them works. The closest I think I got is:
var total = 0;
$.each(cart, function(index, value) {
var myqty = parseInt(qty, 1);
sum += myqty;
});
console.log(total);
But that also doesn't work. Any hints are greatly appreciated. The error I get is:
Uncaught ReferenceError: qty is not defined