have a following function:
listOfTransactions.map(({ tdate='', out='', in='' }) => {
return {
date: '10 Feb 2022',
out: 'AAA
in: 'BBB'
}
})
// Here multiple objects will be returned from here, but the format of the date will be like this only. Now, I need to sort this in a descending order , so I tried
_.sortBy( listOfTransactions.map(({ tdate='', out='', in='' }) => {
return {
date: '10 Feb 2022',
out: 'AAA
in: 'BBB'
}
}) , 'date')
But this is not working .So, any suggestions/ help how do I sort this?
Thanks
According to lodash docs you need to return the value want to sort by. Since it is specifically dates, you first need to convert them to Date objects.
_.sortBy(listOfTransactions, (transaction) => new Date(transaction.date))
I believe this should return what you need.