Remove one item from an array - toSpliced vs filter (v2)

Revision 2 of this benchmark created on


Setup

function *gen() {
	for (let i = 0; i < 1000; i++)
		yield `test${i}val`
}

let arr = new Array(...gen());

const itemValue = 'test500val';

Test runner

Ready to run.

Testing in
TestOps/sec
toSpliced
const itemIndex = arr.findIndex((item) => item === itemValue)
const newArr = arr.toSpliced(itemIndex, 1)
ready
filter

const newArr = arr.filter((val) => val !== itemValue)
ready

Revisions

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