WEB/JavaScript

“javascript sort json array by multiple values” Code Answer

Remoted remoted 2021. 6. 21. 08:07
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;
   });