I am working on a JavaScript project where I need to calculate the sum of each subarray using forEach, map, and reduce functions. My goal is to have an output like this:
sum = [8, 13, 22]
However, despite my efforts, I cannot seem to get the desired outcome. Can someone please help me figure out where I am making a mistake? Thank you.
var Data = [{"a":1,"b":2,"c":5},{"a":3,"b":4,"c":6},{"a":6,"b":7,"c":9}];
var newArr = [];
Data.forEach(function(item) {
item = item.reduce(function(a, b) {
return a + b;
});
newArr.push([item]);
});
console.log(newArr);