replace all occurrences in a string [duplicate] March 9, 2023 by Tarik Use the global flag. str.replace(/\n/g, '<br />');