I have an array of objects which each may have collection of transactions I need to extract two values of the array
- sum value of all objects
- sum amount of all transactions
[
{
"id": "1",
"value": 2343,
"transactions": [
{
"id": 88,
"amount": 34,
},
{
"id": 89,
"amount": 111,
}
]
},
{
"id": "2",
"value": 345,
"transactions": [
{
"id": 90,
"amount": 44,
},
{
"id": 91,
"amount": 112,
}
]
}
]
The first one I achieve by
objects.reduce((acc, transaction) => acc + transaction.value, 0);
But the second one is too difficult for me to achieve; do I loop and reduce each object?