Run details:
Mozilla/5.0 (Linux; Android 9; ANE-LX1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.110 Mobile Safari/537.36
Chrome Mobile 86
Android
Mobile
4 years ago
Test name Executions per second
Массивы 1333.1 Ops/sec
Строки 235005.7 Ops/sec
Slice 240756.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)