I have an object that looks like this:
Object {391:Array[1], 396: Array[2]}
391:
Array[1]
0:
arrival: "17.43.49"
car: "391"
date: "11/11/2014"
duration: "00:00:06"
time: "17.43.43"
396:
Array[2]
0:
arrival: "17.20.48"
car: "396"
date: "11/11/2014"
duration: "00:00:11"
time: "17.20.37"
1:
arrival: "17.21.27"
car: "396"
date: "11/11/2014"
duration: "00:00:17"
time: "17.21.10"
It is constructed by the following function:
var carsDict = {};
angular.forEach($scope.recordlist, function(record) {
carsDict[record.car] = carsDict[record.car] || [];
carsDict[record.car].push(record);
});
$scope.carstats = carsDict;
Is there any way using AngularJS that I can add an substract properties from every object in the array?
For instance, in the example above every object is a trip (391 has one trip, 396 has two trips) from a particular car. Right now I'm listing the car code and the number of trips using an ng-repeat like this:
<div class="row" ng-repeat="carcode in carstats">
<div class="col-md-4">{{carcode[0].car}}</div>
<div class="col-md-4">{{carcode.length}}</div>
</div>
What I'm trying to do is to figure out the total duration time for each car, so I need to be able to add together all the duration properties from every object in every array.
In the example above, every array has to end up having a property totalduration that is the sum of all the duration properties in all the objects of the array. for exampl, the second array should have a 396.totalduration = (duration: "00:00:11") + (duration: "00:00:17")
Any tips?