0

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;
      });
  }
  • 2
    Does this answer your question? [How to sort an array of objects by multiple fields?](https://stackoverflow.com/questions/6913512/how-to-sort-an-array-of-objects-by-multiple-fields) – Jelle Nov 11 '21 at 12:31
  • No, because the accepted answers there is where he sort just by two fields – user17190872 Nov 12 '21 at 08:19

0 Answers0