Run details:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Mobile Safari/537.36
Chrome Mobile 134
Android
Mobile
23 days ago
Test name Executions per second
Массивы 2193.3 Ops/sec
Строки 23346570.0 Ops/sec
Slice 13101584.0 Ops/sec
Script Preparation code:
AخA
 
var position = 20;
var testString = "А еще можно символы в массиве хранить. Сплайсом вставлять символ и джойнить перед выводом";
var testArray = testString.split ``;
var newChar = "X";
Tests:
  • Массивы

     
    testArray.splice(position, 0, newChar);
    let result = testArray.join``;
  • Строки

     
    let result = testString.substring(0, position) + newChar + testString.substring(position)
  • Slice

     
    let result = testString.slice(0, position) + newChar + testString.slice(position)