DEV Community

loading...

Discussion on: What happens when you IndexOf an empty string?

Collapse
turnerj profile image
James Turner Author

You're right, .replace("", "x") and .split("") definitely have ambiguous meanings.

One thought I just had now though is thinking what if replace was using indexOf internally. Without a special case for an empty string, it could easily get stuck replacing the character at index 0 because indexOf said it found it there.

Forem Open with the Forem app