Excuse me I have to ask a stupid question.
$scope.taxInFiveCity = [{
id: 1,
city: 'Taipei',
tax: 32530459
}, {
id: 2,
city: 'NewTaipei',
tax: 19232016
}, {
id: 3,
city: 'Taichung',
tax: 12150909
}, {
id: 4,
city: 'Tainan',
tax: 8322458
}, {
id: 5,
city: 'Kaoshung',
tax: 16069937
}, {
id: 6,
city: 'Total',
//The following is the main part of my difficulty//
tax: $scope.taxInFiveCity[0].tax + $scope.taxInFiveCity[1].tax + $scope.taxInFiveCity[2].tax + $scope.taxInFiveCity[3].tax + $scope.taxInFiveCity[4].tax
//
}];
The above is my code in the controller.js
I create an array in the model of the MVC framework of AngularJS to store the taxes of estate in the main five cities in Taiwan.
Then I want to make the last element in the array be the total. How can I modify my code to calculate the sum of the attributes in the objects in the array and store the sum value in the last objects(total) in the $scope?