a/19500066/1636522

by wared

CSS

*{font-family:Consolas}

JavaScript

var arr1 = [
    {apple: 111, tomato: 55},
    {apple: 222, tomato: 55}
];

var arr2 = [
    {apple: 222, tomato: 55},
    {apple: 333, tomato: 55}
];

var res, i, item, prev;

// merges arrays together
res = [].concat(arr1, arr2);

// sorts the resulting array based on the apple property
res.sort(function (a, b) {
    return a.apple - b.apple;
});

for (i = res.length - 1; i >= 0; i--) {
    item = res[i];

    // compares each item with the previous one based on the apple property
    if (prev && item.apple === prev.apple) {

        // removes item if properties match
        res.splice(i, 1);
    }
    prev = item;
}

document.body.innerHTML = res.map(function (row) {
    return 'apple: ' + row.apple + ', tomato: ' + row.tomato;
}).join('<br/>');