I can't figure out how can I extract the value of an attribute in my objects and then calculate them.
So I have as follow:
const data = [
{
topUp: true, value: 200
},
{
topUp: true, value: 18
},
{
topUp: false, value: 20
},
{
topUp: true, value: 100
},
]
const totalSpending = data.filter(
transaction => transaction.topUp == true
);
Now I should get 3 objects. From here I want to get the value of each one like [200, 18, 100] and add them together so my const totalSpending
will be 318.