title: How to sort array of objects by multiple keys?
body: <p>I have this array:</p>
  <pre><code>let arr = [{
      &quot;guid&quot;: 1,
      creationDateTime: 1632180639045,
      &quot;pricePerUnitPerHour&quot;: 5,
      &quot;awardedSavingCalculationStatus&quot;: 1,
      divisible: true,
  }, {
      &quot;guid&quot;: 2,
      creationDateTime: 2504091567119,
      &quot;pricePerUnitPerHour&quot;: 20,
      &quot;awardedSavingCalculationStatus&quot;: 1,
      divisible: true,
  }, {
      &quot;guid&quot;: 3,
      creationDateTime: 1504095567183,
      &quot;pricePerUnitPerHour&quot;: 5,
      &quot;awardedSavingCalculationStatus&quot;: 1,
      divisible: true,
  }]
  </code></pre>
  <p>I need to make the ascending sorting by these three properties pricePerUnitPerHour, divisible and creationDateTime.</p>
  <p>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.</p>
  <p>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</p>
  <p><strong>what i tried</strong></p>
  <p>i found some answers at stackoverflow but there he makes the sorting by only two fields
  but i can't find a way to sort by third one</p>
  <pre><code> arr.sort(
        function (a, b) {
          if (a.pricePerUnitPerHour === b.pricePerUnitPerHour) {
            return b.divisible - a.divisible;
          }
          if(a.divisible === b.divisible) {
              return new Date(a.creationDateTime) - new Date(b.creationDateTime)
          }
          return a.pricePerUnitPerHour &gt; b.pricePerUnitPerHour ? 1 : -1;
        });
  </code></pre>
  <p>Here the sorting works if the prices and the divisible ones are same then it is sorted by them but on the creationDateTime it is not sorting on ascending order</p>