I'm fairly new to working with arrays and objects. I have the array below that contains multiple objects and those objects contain 1 object called date and 1 nested array called data ( data contains 2 keys, date and expense )
I'm able to map over the array to output what I want.
Problem: I cannot figure out how to sort the array alphabetically from A to Z without destructuring it. I know I should use probably something like this function for the sorting but since it's deeply nested, I cannot seem to properly hit a.expense.
.sort((a, b) => (a.expense > b.expense ? -1 : 1))
What I currently have going on: Lets assume the array is called arr
{arr.map((item) => {
return item.data
.map((d) => (
<div>
<div>{d.expense}</div> <div>{d.date}</div>
</div>
)).sort((a, b) => (a.expense > b.expense ? -1 : 1)) // sorting doesnt work
})}

return item.data.sort(...).map((d) => ...);