replace all occurrences in a string [duplicate]

Use the global flag.

str.replace(/\n/g, '<br />');

Leave a Comment