Run details:
Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0
Firefox 115
Linux
Desktop
one year ago
Test name Executions per second
Array splice 180545.1 Ops/sec
ES6 Object Spread 177.7 Ops/sec
Object property assign 97469616.0 Ops/sec
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'}