unique

Benchmark created by remy on


Setup

const a = [1,2,3,3,3,4,5,5,6,6];

Test runner

Ready to run.

Testing in
TestOps/sec
reduce spread
a.reduce((acc, curr) => (!acc.includes(curr) ? [...acc, curr] : acc), [])
ready
from new set
Array.from(new Set(a))
ready
reduce concat
a.reduce((acc, curr) => (!acc.includes(curr) ? acc.concat(curr) : acc), [])
ready
filter
a.filter((curr, i) => a.indexOf(curr) === i)
ready
reduce push
a.reduce((acc, curr) => (!acc.includes(curr) && acc.push(curr) && acc || acc), [])
ready
filter self
a.filter((curr, i, self) => self.indexOf(curr) === i)
ready
object based
d={}; a.forEach(function(x) { d[x]=true; }); Object.keys(d);
ready
spread set
[...new Set(a)]
ready

Revisions

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