Okay, I need a recursive merge function like the one in PHP
I have these arrays.
const myArray1 = [ [{ “hotel_id”: “84011815”, “city”: “Dubai” }, { “hotel_id”: “84011815”, “offer_id”: “43230076|1|2293” }, { “hotel_id”: “84011815”, “offer_id”: “16013804|4|1643” } ], [{ “hotel_id”: “84011815”, “city”: “Dubai” }, { “hotel_id”: “84011815”, “offer_id”: “28295947|1|1176” }, { “hotel_id”: “84011815”, “offer_id”: “4221802|3|2316” } ] ]
const myArray2 = [ [{ “hotel_id”: “84011815”, “city”: “Dubai” }, { “hotel_id”: “84011815”, “offer_id”: “43230076|1|2293” }, { “hotel_id”: “84011815”, “offer_id”: “16013804|4|1644” } ], [{ “hotel_id”: “84011815”, “city”: “Dubai” }, { “hotel_id”: “84011815”, “offer_id”: “28295947|1|1177” }, { “hotel_id”: “84011815”, “offer_id”: “4221802|3|2319” } ] ]
I want to merge them by hotel_id and make sure all offers are also merged into one resulting array… the result should be like this
[
[
{
“hotel_id”: “84011815”,
“city”: “Dubai”
},
{
“hotel_id”: “84011815”,
“offer_id”: “43230076|1|2293”
},
{
“hotel_id”: “84011815”,
“offer_id”: “16013804|4|1643”
},
{
“hotel_id”: “84011815”,
“offer_id”: “28295947|1|1176”
},
{
“hotel_id”: “84011815”,
“offer_id”: “4221802|3|2316”
}
]
]
any help?