Having two arrays at hand, array1 requires sorting based on its inner key, role, as per array2. Despite attempting various solutions, I have hit a roadblock due to my lack of understanding on the necessary steps to proceed.
The current output for Array1 is as follows:
{
"id":12,
"roles":[
{
"id":12,
"role":"team_player",
"sub_role":null,
"team_meta":{
"default_player_role":{
"pos":null,
"role":"LWB"
}
}
}
],
"user_email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="681f281f461f">[email protected]</a>"
},
{
"id":1575,
"roles":[
{
"id":1672,
"role":"team_player",
"sub_role":null,
"team_meta":{
"default_player_role":{
"pos":null,
"role":"LB"
}
}
}
],
"user_email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="026842682c71">[email protected]</a>"
},
{
"id":1576,
"roles":[
{
"id":1673,
"role":"team_player",
"sub_role":null,
"team_meta":{
"default_player_role":{
"pos":null,
"role":"CAM"
}
}
}
],
"user_email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="084d484d264d">[email protected]</a>",
},
My objective is to reorder the array above based on the sequence provided in:
const array2 = ["LWB", "LB", "CAM"]
The challenge I am facing is that the sorting key in array1 is too nested, and I am struggling to map the "role" from the first array with array2.