Q:

javascript remove final newline from string

var stringWithLineBreaks = `
O boy 
I've got 
Breaks
`;
var stringWithoutLineBreaks = stringWithLineBreaks.replace(/(\r\n|\n|\r)/gm, "");//remove those line breaks
6
st = st.replaceAll("\\s+","")
3
a.replaceAll("\\s+","");
2
//Removing whitespace from String
 var str = "       Hello World!        ";
console.log(str.trim());
 
4
// Remove the trailing newline(s) from a string
str.replace(/\n*$/, "");
0

New to Communities?

Join the community