Unique Array

Benchmark created on


Setup

const arr = Array(1_000).fill(undefined).map((_, i) => i)

Test runner

Ready to run.

Testing in
TestOps/sec
filter => findIndex
arr.filter(
    (v, i) => arr.findIndex(v2 => v === v2) === i
);
ready
Set check
const seen = new Set();
const newArr = [];
arr.forEach(v => {
	if (!seen.has(v)) {
		seen.add(v);
		newArr.push(v);
	}
});
ready
Set spread
[...new Set(arr)]
ready

Revisions

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