Below is an array with objects that need to be sorted:
[
{
"Books": [],
"_id": "5dea9a11a8e1bf301c462ce4",
"FileName": "AAAAA",
"Order": 99999
},
{
"_id": "5dea9864a8e1bf301c462cdb",
"Books": [],
"FileName": "some1",
"Order": 3
},
{
"Books": [],
"_id": "5dea9873a8e1bf301c462ce1",
"FileName": "among3",
"Order": 3
},
{
"Books": [],
"_id": "5dea986ba8e1bf301c462cde",
"FileName": "things2",
"Order": 2
},
{
"Books": [],
"_id": "5dea9a18a8e1bf301c462ce7",
"FileName": "FFFF",
"Order": 99999
},
{
"Books": [],
"_id": "5dea9a1ea8e1bf301c462cea",
"FileName": "BBBB",
"Order": 99999
}
]
The goal is to sort the array by Order first, and if the Order values are the same, then sort alphabetically by FileName.
[
{
"Books": [],
"_id": "5dea986ba8e1bf301c462cde",
"FileName": "things2",
"Order": 2
},
{
"Books": [],
"_id": "5dea9873a8e1bf301c462ce1",
"FileName": "among3",
"Order": 3
},
{
"_id": "5dea9864a8e1bf301c462cdb",
"Books": [],
"FileName": "some1",
"Order": 3
},
{
"Books": [],
"_id": "5dea9a11a8e1bf301c462ce4",
"FileName": "AAAAA",
"Order": 99999
},
{
"Books": [],
"_id": "5dea9a1ea8e1bf301c462cea",
"FileName": "BBBB",
"Order": 99999
},
{
"Books": [],
"_id": "5dea9a18a8e1bf301c462ce7",
"FileName": "FFFF",
"Order": 99999
},
]
I have managed to achieve this using multiple loops but seeking an optimized solution. Any suggestions or optimized JavaScript/TypeScript code would be greatly appreciated. Thanks!