My dilemma involves working with a dynamically generated array, where I need to extract only the values from the last array for aggregation purposes, discarding all others.
Imagine a structure similar to this:
let target = []
let data = [
[ { name: 'something',
total: 100,
number: 100,
category: 'smh' } ],
[ { name: 'something',
total: 200,
number: 200,
category: 'smh' } ]
]
let arrLength = data.length
target.push(data.splice(0, arrLength, -1))
The final element always contains the aggregated entries of the entire array,
I am struggling with how to consistently push only the last ARRAY into the target-array so that I obtain data that is an aggregation of all previous arrays?
desired outcome
[ { name: 'something',
total: 200,
number: 200,
category: 'smh' } ]