Ive simplified code a bit to narrow the issue.
In this fiddle https://jsfiddle.net/htzLe0wt/ I target all lowercase p in array. They targeted correctly, condition evaluates true twice and we have splice doing change twice too. This is an intention, everything alrgiht.
However when i set parameter of splice howmany to 0 i have a problem. https://jsfiddle.net/htzLe0wt/2
By documentation the only difference that should be is that i add new letter without replacing (item).
So i expect that i will have something like this
thisissp inaltap .
However code gives very different output.
-
First problem it doesnt do changes at respective positions of âpâ - like in first fiddle. As seen in https://jsfiddle.net/htzLe0wt/2 change will occur ALL IN ONE PLACE. At âfirst stopâ, at first lowercase p.
-
Change will not occur twice (which we expect from testing splice with our first fiddle with THE VERY SAME CONDITION) it will occure 8 times.
So why is setting parameter howmany of splice to 0 in this situation giving this strange output when the only difference with first fiddle should be that it adds things without removing items?