Answers for "sort array of objects by 2 key value"

1

sort array of objects by 2 key value

homes.sort(
   function(a, b) {          
      if (a.city === b.city) {
         // Price is only important when cities are the same
         return b.price - a.price;
      }
      return a.city > b.city ? 1 : -1;
   });
Posted by: Guest on June-05-2020

Code answers related to "sort array of objects by 2 key value"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language