filmov
tv
javascript - How do I replace all line breaks in a string with br / elements?

Показать описание
#short
#javascript
How can I read the line break from a value with JavaScript and replace all the line breaks with br / elements?
Example:
A variable passed from PHP as below:
"This is man.
Man like dog.
Man like to drink.
Man is the king."
I would like my result to look something like this after the JavaScript converts it:
#javascript
How can I read the line break from a value with JavaScript and replace all the line breaks with br / elements?
Example:
A variable passed from PHP as below:
"This is man.
Man like dog.
Man like to drink.
Man is the king."
I would like my result to look something like this after the JavaScript converts it: