I have two arrays of objects that need to be sorted based on the value of a key in the other array.
array1: [
{
group: 'GROUP1',
sort_order: 1,
},
{
group: 'GROUP2',
sort_order: 2,
},
{
group: 'GROUP3',
sort_order: 3,
}
],
array2: {
'GROUP3' : [
{
"price": 10,
"amount": 2,
},
{
"price": 45,
"amount": 7,
},
],
'GROUP2' : [
{
"price": 10,
"amount": 2,
},
{
"price": 45,
"amount": 7,
},
],
'GROUP1' : [
{
"price": 10,
"amount": 2,
},
{
"price": 45,
"amount": 7,
},
]
}
Now, I need to rearrange the indexes of array2 based on the "sort_order" in array1.
I'm anticipating the order of array2 to be something like GROUP1, GROUP2, GROUP3.
Thank you in advance!