javascript remove final newline from string

JavaScript
var stringWithLineBreaks = `
O boy 
I've got 
Breaks
`;
var stringWithoutLineBreaks = stringWithLineBreaks.replace(/(\r\n|\n|\r)/gm, "");//remove those line breaksst = st.replaceAll("\\s+","")a.replaceAll("\\s+","");// Remove the trailing newline(s) from a string
str.replace(/\n*$/, "");
Source

Also in JavaScript: