Check out example codes for "sort array of objects by 2 key value". It will help you in understanding the concepts better.

Code Example 1

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;
   });

Learn ReactJs, React Native from akashmittal.com