I have an array of objects that contain the data I want to sort (it has more properties), like so:
[
{
"data": {
"id": "green"
}
},
{
"data": {
"id": "red"
}
},
{
"data": {
"id": "blue"
}
}
]
id is a nested property I need to use in order to sort based on scores provided from a different object like so:
{
"green": 5,
"red": 3,
"blue": 8
}
I'm trying to find the best way to sort my array of object, however no success so far.
data.sort((a,b) => scores[a.data.id]-scores[b.data.id]);for descending where data is the array u need to sort. switch a and b for ascending