I'm currently exploring the possibility of achieving this using javascript.
In my scenario, I have an array named cart that consists of objects with product.quantity, and I aim to incorporate the value of cart.length in a calculation. However, I consistently encounter NaN as the result, despite knowing that the data type is a number. Would appreciate any assistance available.
Below are my attempts:
$scope.getCartTotals = function() {
var totalInCart = 0;
cartCount = $scope.cart.length;
$scope.cart.forEach(function(product) {
totalInCart += cartCount * product.quantity;
});
return totalInCart;
};
<body ng-controller="StoreController">
<div ng-show="cart.length > 0">{{getCartTotals()}}</div>
</body>