I have tried various different string.insert(i, s)
functions but none of them have worked with the loop that I have. Here is an example of my code:
var str = " absolutely pie";
var indices = [0, 12, 16]; // indices where I want to insert
var things = ["I", "love", 1]; // things I want to insert
for(var i = 0; i < indices.length; i++) {
str = str.splice(indices[i], 0, things[i]);
}
This doesn't work. It's supposed to print out "I absolutely love pie1" , but instead it prints out:
"I absolutellove1y pie"
You can see the code here.
I have tried most of the examples from this question.
So what's the problem (is it how the insert methods are implemented?), and how can I fix this?