JavaScript Newline Character

Split it on /\r?\n/, in case the string includes the carriage returns with newlines.

join it with '\n', in any browser and any os.


If you want to join using newline characters, just do:

lines.join("\r\n");

But if you want to display on the HTML page, you'd want to wrap each line in <p></p> tags:

html = "<p>" + lines.join("</p><p>") + "</p>";

You can use the Array object's join method to glue together array elements into a string:

lines.join("\r\n");

In CSS: remember to use

white-space: pre;

Tags:

Javascript