I've been trying to sort a nested array, but I'm having trouble with it. It works when I specify the index, but that's not ideal...I need to loop through all values.
Array
items= [{
app_type_id: 1,
apps: [{
app_id: 3,
app_type_id: 1,
app_name: "Test1"
},
{
app_id: 2,
app_type_id: 1,
app_name: "Test2"
},
{
app_id: 107,
app_type_id: 1,
app_name: "Test3"
}
}]
}]
TS
this.iarray[0].apps.sort((a, b) => a.app_name[0] > b.app_name[1] ? 1 : -1)
The current code only sorts the first two items, but in reality, there could be more (dynamic) apps. How can I modify it to sort through all apps?