I have input like this. I tried some solutions. But it doesn't work. I need to merge same invoice_nr objects to one array. Also I need other objects another array. All arrays must be another array.
const result = [
{
invoice_nr: 16,
order_id: 5577,
color: 'red'
},
{
invoice_nr: 16,
order_id: 5577,
color: 'yellow'
},
{
invoice_nr: 17,
order_id: 5574,
color: 'green'
},
{
invoice_nr: 18,
order_id: 5578,
color: 'yellow'
},
{
invoice_nr: 18,
order_id: 5578,
color: 'blue'
}
];
But, I need output like this. How can I achieve that in javascript? Array must be like this.
const result = [
[
{
invoice_nr: 16,
order_id: 5577,
color: 'red'
},
{
invoice_nr: 16,
order_id: 5577,
color: 'yellow'
}
],
[
{
invoice_nr: 17,
order_id: 5574,
color: 'green'
}
],
[
{
invoice_nr: 18,
order_id: 5578,
color: 'yellow'
},
{
invoice_nr: 18,
order_id: 5578,
color: 'blue'
}
]
];