javascript sort array of objects with same key value code example
Example 1: javascript sort array of objects by key value
arr.sort((x, y) => x.distance - y.distance);
Example 2: 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;
});