Given an array of objects:
var arr = [
{a: "foo", b: "bar", c: "baz" },
{a: "foo", b: "bar", c: "qux" },
{a: "foo", b: "bar", c: "baz" },
{a: "foo", b: "bar", c: "qux" },
{a: "bar", b: "foo", c: "qux" },
{a: "bar", b: "qux", c: "foo" },
{a: "bar", b: "foo", c: "qux" }
];
The array shall be filtered so only the unique objects remain:
var arr = [
{a: "foo", b: "bar", c: "baz" },
{a: "foo", b: "bar", c: "qux" },
{a: "bar", b: "foo", c: "qux" },
{a: "bar", b: "qux", c: "foo" }
];
For arrays of plain strings, I use
arr.filter(function (value, index, self) {
return self.indexOf(value) === index;
}
but this doesn't work on objects. All properties must be compared in my case. I guess some sort of deep comparision is needed?