I'm a beginner with React and i want to sorting an array by two filters :
{folder.actions
.sort((a,b) => {
return a.date_actual - b.date_actual || a.date_sched - b.date_sched
})
.map(action => {
...
This code doesn't work, i want to sort by descending and mixed two dates type "date_actual" and "date_sched" with map function and not :
...
<Col xs={4}>
{action.date_actual ?
new Date(action.date_actual).toLocaleDateString() :
new Date(action.date_sched).toLocaleDateString()
}
</Col>
...
18/04/2021 (date_sched)
03/11/2020 (date_actual)
18/04/2021 (date_sched)
03/11/2020 (date_actual)
03/11/2020 (date_actual)
03/11/2020 (date_actual)
12/04/2021 (date_sched)
03/11/2020 (date_actual)
03/11/2020 (date_actual)
Thanks for your time and your help !
sortBy()method is one and would easily do what you need. lodash.com/docs/4.17.15#sortBydate_actualhas a value ordate_schedhas a value).