2
Good morning, I have a question where I have an array of objects as follows, for example:
var producao = [{data: '2019-12-19', producao_ok: 10, producao_nok: 20}, {data: '2018-10-01', producao_ok: 5, producao_nok: 1}, {data: '2019-12-19', producao_ok: 100, producao_nok: 2}, {data: '2018-10-01', producao_ok: 100, producao_nok: 10}, {data: '2019-12-19', producao_ok: 10, producao_nok: 20}];
Is there any way, for example with reduce, to sum up the production values and output by grouping dates, bearing in mind that I have no idea of the initial and final dates of the object?
example of expected result after inserting into a new array:
var objetoNovo = [{data: '2019-12-19', producao_ok: 120, producao_nok: 42}, {data: '2018-10-01', producao_ok: 105, producao_nok: 11}];
Have you considered using a key/value data structure, for example a map?
– Adriano Gomes