Is \n
the universal newline character sequence in Javascript for all platforms? If not, how do I determine the character for the current environment?
I'm not asking about the HTML newline element (<BR/>
). I'm asking about the newline character sequence used within JavaScript strings.
Prints:
I had the problem of expressing newline with \n or \r\n.
Magically the character \r which is used for carriage return worked for me like a newline.
So in some cases, it is useful to consider \r too.
yes use \n, unless you are generating html code, in which you want to use
<br />
I believe it is -- when you are working with JS strings.
If you are generating HTML, though, you will have to use
<br />
tags (not\n
, as you're not dealing with JS anymore)you can use
<br/>
and thedocument.write/
,document.writeln
one.It might be easiest to just handle all cases of the new line character instead of checking which case then applying it. For example, if you need to replace the newline then do the following: