You can do that using replace() with a regular expression:
That regular expression will remove all instances of
\r in your string.
Those three versions will cover different encodings for these operating systems:
- Windows (
- Linux (
- Apple (
You can also remove just instances of
\r\n line breaks in your string with this:
string.replace(/\n/gm, ""); string.replace(/\r/gm, ""); string.replace(/\r\n/gm, "");
Each of those would only remove one of the three types of line-break characters.
Thanks for reading and happy coding!