I understand how to sort an an array of objects by one property, but not how to re-sort the array again alphabetically (while keeping the sorting by property).
For example, I have an array:
[
{title: 'Hello', category: 'something'},
{title: 'Good', category: 'something else'},
{title: 'Monday', category: 'something'},
{title: 'Evening', category: 'something'}, {title: 'Food', category: 'others'}
]
To sort the array by category:
array.sort(
(a, b) => -b.category.localeCompare(a.category)
)
However, how can I sort the items in each category alphabetically, in this array, while keeping the elements sorted by the category?