In Javascript, I have a generated string containing multiple lines, all ending in a newline, for example: "line1\nline2\nline3\n"
What is the best way to cut off the ending newline such that I get "line1\nline2\nline3"
?
For safety, it would be preferrable if the last character is only cut off if it actually is a newline. So if my input is "field1=5\nfield2=abc\nfield3= some string \n"
I want to remove the last newline but keep the two spaces.