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

Popular posts from this blog

php - trouble displaying mysqli database results in correct order -

depending on nth recurrence of job in control M -

sql server - Cannot query correctly (MSSQL - PHP - JSON) -