merge two array of objects based on a key code example
Example 1: sort array of objects by 2 key value
homes.sort(
function(a, b) {
if (a.city === b.city) {
return b.price - a.price;
}
return a.city > b.city ? 1 : -1;
});
Example 2: js combine 2 array to object key value
var columns = ["Date", "Number", "Size", "Location", "Age"];
var rows = ["2001", "5", "Big", "Sydney", "25"];
var result = rows.reduce(function(result, field, index) {
result[columns[index]] = field;
return result;
}, {})
console.log(result);