I was messing around with the following bit of code:
var x = [“a”, “b”, “c”, “d”];
var y = x.splice(0, 3, “string”);
With this set up I was getting [“a”, “b”, “c”] printed out.
As I understand, the first argument in the splice function is the index where the operation will begin. The second (optional) argument is for how many elements will be removed. Then the arguments which follow are the elements that are to be added.
I was messing around with the parameters and the splice function was not behaving the way I expected. It seemed to be behaving more like a slice, which is confusing.
Anyways, I hope someone can clear this up for me. I feel like I’m missing something obvious here