Remove By Index and update all with objects

Benchmark created on


Setup

const getObj = (val) => ({
	id: `id#${val}`,
	value: val,
});
const testArr = [getObj(0), getObj(7), getObj(24), getObj('remove'), getObj(600)];
const index = 3;
const update = (val) => ({...val, value: val.value*2});

Test runner

Ready to run.

Testing in
TestOps/sec
Clone Splice Map
const result = [...testArr].splice(index,1).map(update);
ready
Two Slice Map
const result = [...testArr.slice(0, index), ...testArr.slice(index)].map(update);
ready
Filter Map
const result = testArr.filter((_, i) => i !== index).map(update);
ready
Reduce
const result = testArr.reduce((acc, v, i) => 
{
	if(i !== index) { 
        acc.push(update(v));
    }
    return acc;
}, []);
ready
ToSpliced Map
const result = testArr.toSpliced(index, 1).map(update);
ready

Revisions

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