I've been attempting to group this array by the "dataPrin" field for some time now, but without success.
It's worth noting that there are two instances of the "dataPrin" field displaying the same date.
My goal is to organize this array in a way that if there are duplicate "dataPrin" fields with the same date, they should be grouped into one entry, just like the example provided below.
Is it feasible to achieve this using 'reduce'? I would greatly appreciate any assistance from the community.
Here is the current array:
[{
"dataPrin": "2021-05-31T16:10:28-03:00",
"selectAll": false,
"lancamentos": [{
"cod_transacao": 1510,
"num_cpf_cnpj": "11.414.555/0001-04",
"dt_lancamamento": "2021-05-31T16:29:28-03:00",
}]
},
{
"dataPrin": "2021-05-29T16:30:28-03:00",
"selectAll": false,
"lancamentos": [{
"cod_transacao": 1511,
"num_cpf_cnpj": "11.414.555/0001-04",
"dt_lancamamento": "2021-05-31T16:29:28-03:00",
}]
},
{
"dataPrin": "2021-05-29T16:15:28-03:00",
"selectAll": false,
"lancamentos": [{
"cod_transacao": 1512,
"num_cpf_cnpj": "11.414.555/0001-04",
"dt_lancamamento": "2021-05-31T16:29:28-03:00",
}]
}]
Desired output:
[{
"dataPrin": "2021-05-31T16:10:28-03:00",
"selectAll": false,
"lancamentos": [{
"cod_transacao": 1510,
"num_cpf_cnpj": "11.414.555/0001-04",
"dt_lancamamento": "2021-05-31T16:29:28-03:00",
}]
},
{
"dataPrin": "2021-05-29T16:30:28-03:00",
"selectAll": false,
"lancamentos": [{
"cod_transacao": 1511,
"num_cpf_cnpj": "11.414.555/0001-04",
"dt_lancamamento": "2021-05-31T16:29:28-03:00",
},
{
"cod_transacao": 1512,
"num_cpf_cnpj": "11.414.555/0001-04",
"dt_lancamamento": "2021-05-31T16:29:28-03:00",
}]
}]