Get distinct objects from array

Benchmark created on


Setup

const arr = [
    { id: '1a405da0-fe5e-4fa6-8bd6-2ee7cc763f06', name: 'Foo' },
    { id: '1a405da0-fe5e-4fa6-8bd6-2ee7cc763f06', name: 'Foo' },
    { id: '2dbfc92a-b7ee-41ea-b4ea-f869906922fa', name: 'Bar' },
];

Test runner

Ready to run.

Testing in
TestOps/sec
Using `Map`
return [...new Map(arr.map(item => [item.id, item])).values()];
ready
Using `filter` and `findIndex`
return arr.filter((value, index, self) => self.findIndex((m) => m.id === value.id) === index);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.