I have an array of objects that contains numeric values. When I loop through it I need to set in the following logic the values in a way that each value starting from second element is equal to the previous value -80
result.data.forEach((dataItem) => {
if (dataItem.values && dataItem.values.length) {
dataItem.sumValue = dataItem.values.reduce((sum, item) => {
return (sum + item.value)
}, 0)
} else dataItem.sumValue = dataItem.value
So each dataItem.sumValue should be equal to the previous value -80.
How can it be achieved?