I am trying to merge an array of products
with the same order_id
but also adding all the object of the second products
array. Here is an example of my orders.
const orders = [
{
"order_details": {
},
"order_id": "1",
"order_status": "Pending",
"order_type": "drugs",
"products": [
{
"name": "product xyz"
}
],
},
{
"order_details": {
},
"order_id": "2",
"order_status": "Pending",
"order_type": "Prescriptions",
"products": [
{
"name": "product abc"
}
],
},
{
"order_details": {
},
"order_id": "1",
"order_status": "Pending",
"order_type": "goods",
"products": [
{
"name": "product ghj"
}
],
},
]
and this is what I want to transform it into
const orders = [
{
"order_details": {
},
"order_id": "1",
"order_status": "Pending",
"order_type": "drugs & goods",
"products": [
{
"name": "product xyz"
},
{
"name": "product ghj"
}
],
},
{
"order_details": {
},
"order_id": "2",
"order_status": "Pending",
"order_type": "Prescriptions",
"products": [
{
"name": "product abc"
}
],
}
]