The easiest approach is using regular expressions to detect and replace newlines in the string. In this case, we use replace function along with string to replace with, which in our case is an empty string.
1 2 3 | function remove_linebreaks( var message ) { return message.replace( /[\r\n]+/gm, "" ); } |
In the above expression, g and m are for global and multiline flags.
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.