Receiving information from an API and looking to aggregate the values it contains. Consider the following code snippet:
function totalPesos(){
$http.get('/api/valueForTest')
.then(function(data){
$scope.resumePesos = data.data.Response;
//console.log($scope.resumePesos);
}
The response retrieved is:
[{Id: 60, Name: Chuck, Quantity: 300},
{Id: 61, Name: Arthur, Quantity: 199},
{Id: 62, Name: John, Quantity: 450}]
The goal is to sum the Quantity
. How can this be achieved? An attempt with the following code was made:
$scope.resumePesos.reduce(function(a,b){return a + b; });
However, the result obtained was [object Object]