SyntaxFix
Write A Post
Hire A Developer
Questions
Use the global flag.
str.replace(/\n/g, '<br />');