From this original question, how would I apply a sort on multiple fields?
Using this slightly adapted structure, how would I sort city (ascending) & then price (
for a non-generic, simple solution to your exact problem:
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; });