Script Preparation code:
AخA
 
var input = [];
for (var i = 0; i < 50000; i++) {
    input.push({
        id: i,
        data: 'something'
    })
}
Tests:
  • Array splice

     
    const index = input.findIndex(val => val.id === 999);
    input.splice(index, 1, {id: 999, data: 'somethingElse'});
  • ES6 Object Spread

     
    input = {
        ...input,
        [999]: {id: 999, data: 'somethingElse'}
      }
  • Object property assign

     
    input[999] = {id: 999, data: 'somethingElse'}
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Array splice
    ES6 Object Spread
    Object property assign

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 28 days ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Chrome 131 on Windows
View result in a separate tab
Test name Executions per second
Array splice 1435029.6 Ops/sec
ES6 Object Spread 10134.6 Ops/sec
Object property assign 63001104.0 Ops/sec