Is not in a single statement but is short.
var a = [{a: 1, b: 2}, {a: 1, b: 2}, {c: 3, d: 4}];
a = a.filter((value, index, array) =>
!array.filter((v, i) => JSON.stringify(value) == JSON.stringify(v) && i < index).length);
console.log(a);
Your question sees like this:
Delete duplicated elements in array of objects Javascript
But like in the comment will fails for:
var a = [{a: 1, b: 2}, {b: 2, a: 1}];
You need a custom compare for your case:
function isEqual(a, b){
for(var i in a)
if(a[i] != b[i])
return false;
for(var i in b)
if(b[i] != a[i])
return false;
return true;
}
var a = [{a: 1, b: 2}, {b: 2, a: 1}, {c: 3, d: 4}];
a = a.filter((value, index, array) =>
!array.filter((v, i) => isEqual(value, v) && i < index).length);
console.log(a);
You can compare ids or somenthing like this to identify equal object in this sample i just compare the properties.
Like @Juan Mendes said in comment:
The reason your code doesn't filter elements is because two similar objects are still considered different objects because they point to different objects. You need to write your own code that uses a custom comparator.
{foo:3} !== {foo:3}.