Remove duplicate object from array

Remove duplicate array object from array

by Pankaj Sapkal

JavaScript

var subservices = [{
    "name": "hello",
    "label": "world"
}, {
    "name": "abc",
        "label": "xyz"
}, {
    "name": "hello",
        "label": "world"
}];

var result = [];

$.each(subservices, function (i, e) {
    var matchingItems = $.grep(result, function (item) {
       return item.name === e.name && item.label === e.label;
    });
    if (matchingItems.length === 0) result.push(e);
});

alert(JSON.stringify(result));