Answers for "sort objects by one key"

8

javascript sort array of objects by key value

arr.sort((x, y) => x.distance - y.distance);
Posted by: Guest on March-15-2020
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 objects by one key"

Code answers related to "Javascript"

Browse Popular Code Answers by Language