Line breaks using javascript strings

I am breaking a string in javascript using \ n, for example: -

text = "this is a test" + "\ n" + "another test";

and show that in html i m using code

text = text.replace('\n' , '<br>');

but text i m gets without br

when checking in firebug console I get line breaks (\ n is not displayed except for a new line)

how can I place line breaks using \ n or should I do some kind of custom code instead of \ n

thank

+3
source share
3 answers
var newText = text.replace(/\n/g , "<br>");
+2
source

use double quotes to avoid \ n

try the following:

text = text.replace("\n" , "<br>");
+3
source

/\ r\n | [\ r\n]/g - , . .

+2
source

Source: https://habr.com/ru/post/1782671/


All Articles