I want to create a sort-by function to sort the ice creams by taste either asc or desc. My issue is that I have trouble accessing the tastes dynamically. I can access individual taste values via iceCreams[0].taste
, but this is no good if I want to create a sort by button:
state = {
iceCreams: [
{
name: 'Zap',
taste: 6,
img:
'blah1'
},
{
name: 'Feast',
taste: 8,
img:
'blah2'
},
{
name: 'Mini-Milk',
taste: 2,
img:
'blah3'
}
]},