Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
how-to-insert-a-string-at-a-specific-index-in-javascript 2
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser:
Chrome 121
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Benchmark engine:
Benchmark.js
slcie
12.2M/s
splice
4.2M/s
View exact numbers
Test name
Executions per second
✓
slcie
12,172,210 Ops/sec
splice
4,175,572 Ops/sec
Tests:
slcie
let origString = "GeeksGeeks"; let stringToAdd = "For"; let indexPosition = 5; newString = origString.slice(0, indexPosition) + stringToAdd + origString.slice(indexPosition);
splice
let origString = "GeeksGeeks"; let stringToAdd = "For"; let indexPosition = 5; // Split the string into individual // characters origString = origString.split(''); // Insert the string at the index position origString.splice(indexPosition, 0, stringToAdd); // Join back the individual characters // to form a new string newString = origString.join('');