I have the following array
let arr = [
{
"creationDateTime": 1632180639045,
"pricePerUnitPerHour": 12,
"divisible": false,
},
{
"creationDateTime": 2504091567119,
"pricePerUnitPerHour": 12,
"divisible": true,
},
{
"creationDateTime": 1504095567183,
"pricePerUnitPerHour": 5,
"divisible": true,
},
]
I need to make the ascending sorting by these three properties pricePerUnitPerHour/divisible/and creationDateTime
So if for example two objects are having equal values in pricePerUnitPerHour
then the sorting shoould be by divisible property. There divisible:true
should be before the object where we have divisible:false
.
And on the end if they have two equal prices, divisible property is true for example the sorting should be done based on the timestamp - creationDateTime
I got stuck at
tableSort() {
this.searchFilteredData.sort(
function (a, b) {
return b.pricePerUnitPerHour - a.pricePerUnitPerHour;
});
}