javascript - Make sum of object properties from array -
i have sum of unit_price numbers. how can that?
the array looks this:
$scope.items = [ { id: '1', name: 'phone', quantity: '1', unit_price: '200' }, { id: '2', name: 'iphone', quantity: '1', unit_price: '240' } ];
you reduce
array:
var total = $scope.items.reduce(function(x,y) { return x + parseint(y.unit_price) }, 0);
Comments
Post a Comment