Whenever you get Javascript to interpret this line, "\ n" will be displayed as a new line (this is one character, which means length).
To use a string as a backslash literal-n, try backsliding with a different one. For example:
"Line 1\\nLine 2"
If you cannot do this when a line is created, you can include one line in another:
"Line 1\nLine 2".replace(/\n/, "\\n");
If you can have multiple occurrences of a new line, you can get them all at once by making a global regular expression, for example:
"Line 1\nLine 2\nLine 3".replace(/\n/g, "\\n");
Jon carter
source share