Using for..in to iterate object and reduce to iterate array

var data = [{costOfAirtickets: 2500, costOfHotel: 1200},{costOfAirtickets: 1500, costOfHotel: 1000}];

var result = [data.reduce((acc, n) => {
  for (var prop in n) {
    if (acc.hasOwnProperty(prop)) acc[prop] += n[prop];
    else acc[prop] = n[prop];
  }
  return acc;
}, {})]
console.log(result)

Answer from Chris Li on Stack Overflow
🌐
Expert Code Blog
expertcodeblog.wordpress.com › 2018 › 10 › 31 › typescript-sum-of-object-properties
TypeScript: sum of object properties within an array | Expert Code Blog
October 31, 2018 - We need to use the map method (that creates a new array with the results of calling a provided function on every element in the calling array) to obtain another objects array that contains only this properties values, and after this we can use ...
🌐
GitHub
gist.github.com › benwells › 0111163b3cccfad0804d994c70de7aa1
Using Array.reduce to sum a property in an array of objects · GitHub
items = [ { customer_id: 1, id: 1, sum: 123} { customer_id: 1, id: 2, sum: 321} { customer_id: 1, id: 3, sum: 213}, ] var total_sum = items.reduce(function(prev, cur) { return prev + cur.summ; }, 0); console.log(total_sum) -> `NaN` %(
🌐
GitHub
github.com › angular › code.angularjs.org › blob › master › 0.9.10 › docs-0.9.10 › angular.Array.sum.html
code.angularjs.org/0.9.10/docs-0.9.10/angular.Array.sum.html at master · angular/code.angularjs.org
April 13, 2022 - it is evaluated once for each element in <code>array</code> and then the sum of these values is returned.</p> ... <div class="usage"><div ng:non-bindable=""><pre class="brush: js; html-script: true;">angular.Array.sum(array[, expression]);</pre>
Author   angular
🌐
Stack Overflow
stackoverflow.com › questions › 68337328 › how-to-sum-the-properties-of-an-object-in-angular
How to sum the properties of an object in Angular
The sub total field is supposed ... object. How can i achieve this? ... Sub Total is sum of Target only, and Total = Target + Actual + Incentive....
🌐
Stack Overflow
stackoverflow.com › questions › 42337954 › how-to-get-sum-of-objects-properties
angularjs - How to get sum of objects' properties - Stack Overflow
February 20, 2017 - var app= angular.module("MyApp", []); app.controller("MyController", function($scope) { $scope.data = [ { "id":"fam1", "age":2, "btaccident":0.79, "btdisability":0.13, "btdeath":0.18, "premium":5 }, { "id":"fam2", "age":3, "btaccident":0.79, "btdisability":0.13, "btdeath":0.18, "premium":5 } ]; $scope.sum = function(){ var total = 0; angular.forEach($scope.data,function(key,value){ total+=key.premium; }) return total; } });
Find elsewhere
🌐
Digital Craftsman
blog.digital-craftsman.de › sum-numbers-in-array-of-objects-with-typescript
Sum numbers in array of objects with Typescript
April 27, 2020 - get numberOfUnhandledHours() { return this.timeEntries .filter((timeEntry: TimeEntry) => !timeEntry.approvedAt && !timeEntry.rejectedAt) .reduce((sum: number, b: TimeEntry) => sum + b.numberOfHours, 0); }
🌐
Stack Overflow
stackoverflow.com › questions › 52410630 › sum-of-object-field-in-html-angular
sum of object.field in html / angular? - Stack Overflow
0 Get the sum of specific value of object in angularjs · 0 Angularjs ng-repeat sum the fields · 0 Totalling Calculated fields with AngularJS · 2 Angular 2: Calculate sum of an element in ngFor · 0 Angularjs ng-value sum fields · 3 Calculating sum using Angular · 1 Summing properties in an object array Angular ·