Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

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;
   });
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #sort #array #objects #key
ADD COMMENT
Topic
Name
3+4 =