I have the following json data:
data = [
{
stateCode: 'CH',
startDate: new Date('06/12/2020 08:00'),
startDateWithDelay: new Date('06/12/2020 08:00'),
},
{
stateCode: 'LA',
startDate: new Date('06/12/2020 08:00'),
startDateWithDelay: new Date('06/12/2020 08:30'),
},
{
stateCode: 'NY',
startDate: new Date('06/12/2020 06:00'),
startDateWithDelay: new Date('06/12/2020 06:00')
}
]
The data should be sorted by startDate by default. But if the startDate for 2 records is same then it should be sorted by stateDateWithDelay property. In the above example, startDate for first 2 records is same. So, in that case it should be sorted based on startDateWithDelay property.
After sorting the result should display the following states based on the 2 dates:
New York NY Chicago CH Los Angeles LA
I am using the following code to sort based on the startDate
import { sortBy } from 'lodash-es'
data = data.sortBy(data, (obj) => obj.startDate);
How do the accomplish sorting by the startDateWithDelay property when startDate is same for first 2 records.
Thanks