The array consists of objects like these
[
{
name: 'john',
date: '21-07-2020',
car: 'bmw'
},
{
name: 'fred',
date: '14-10-2020',
car: 'tesla'
}
]
I am trying to sort it in ascending order using Moment's isBefore
function but it isn't working, using Moment library:
array.sort((a, b) => moment(a.date, 'DD-MM-YYYY').isBefore(moment(b.date, 'DD-MM-YYYY')))
Use Moment's diff
array.sort((a, b) => moment(a.date, 'DD-MM-YYYY').diff(moment(b.date, 'DD-MM-YYYY')))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With