I'd like to sum objects from array, I've been searching and testing different things founds around there, using Lodash or not, without any success.
Here is the data array, there is 5 elements but it could be less or more. The properties will always be the same, but there could be a lot more.
const data = [
{
from: "2019-10-15",
stats: [
{
options: {
width: 15,
height: 20,
borders: 35,
removable: 5
}
}
]
},
{
from: "2019-10-16",
stats: [
{
options: {
width: 22,
height: 18,
borders: 10,
removable: 0
}
}
]
},
{
from: "2019-10-17",
stats: [
{
options: {
width: 0,
height: 15,
borders: 15,
removable: 0
}
}
]
},
{
from: "2019-10-18",
stats: [
{
options: {
width: 20,
height: 20,
borders: 10,
removable: 5,
}
}
]
},
{
from: "2019-10-19",
stats: [
{
options: {
width: 0,
height: 10,
borders: 0,
removable: 30
}
}
]
}
];
The expected result is the sum of each array element stats[0].options properties:
const sum = {
width: 57,
height: 83,
borders: 70,
removable: 40
}
I know it's definitely not complicated.