Better way to sum a property value in an array

后端 未结 16 1452
遥遥无期
遥遥无期 2020-11-22 02:41

I have something like this:

$scope.traveler = [
            {  description: \'Senior\', Amount: 50},
            {  description: \'Senior\', Amount: 50},
             


        
16条回答
  •  甜味超标
    2020-11-22 03:37

    can also use Array.prototype.forEach()

    let totalAmount = 0;
    $scope.traveler.forEach( data => totalAmount = totalAmount + data.Amount);
    return totalAmount;
    

提交回复
热议问题