This is for something else, but I put together an example to show this problem.
Note: I want to remove all occurrences of "o", an coincidentally it seemed to look like i wanted to remove only the character at the end of the string - i thought there was a bug with not being able to remove the last character (and that replace
replaced all occurrences).
var s = "hollo";
console.log(s);
s = s.replace("o", "");
console.log(s)
This happens on Chrome and Firefox which are the only browsers I've tested it with.
I get this in the console
hollo
hllo
Why does it do this?
Edit: This seems to fix the problem:
if (s.lastIndexOf("o") != -1) s = s.substr(0, s.length - 1);
But I still want to know why exactly this happens.