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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.