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

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -