Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
'use strict';
function getDistinctObjArray(arr) {
var distinctArr = arr.filter(function(el) {
var isDup = el.inArray;
el.inArray = true;
return !isDup;
});
distinctArr.forEach(function(el) {
delete el.inArray;
});
return distinctArr;
}
var p = [{
a: 1
}, {
a: 1
}, {
a: 1
}, {
b: 1
}, {
b: 1
}, {
a: 1
}, {
c: 1
}, {
a: 1
}, {
d: 1
}, {
a: 1
},
];
var x = getDistinctObjArray(p);
if(p.length === x.length)
alert('Duplicates were not removed');
else
alert('Dupilcates were removed');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.