javascript replace newline

function nl2br(str){
return str.replace(/(?:\r\n|\r|\n)/g, '<br>');
}
var stringWithNewLines= `Well this is a
a very broken
sentance`;
var stringWithBrs=nl2br(stringWithNewLines);
// stringWithBrs= "Well this is a<br>a very <br>broken<br>sentance"

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
javascript replace string with new line javascript replace br tag with newline javascript replace br tag with new line how to replace new line in js javascript replace new line character replace /n with line breaks js replace java new line with br javascript replace \n from string js javascript replace new line in string javascript replace r n with br replace string with new line in javascript replace /n with newline js replace break line javascript js replace newline with p element replace endline in string js convert text with to html javascript js replace new line br replace new line javascript replace with newline javascript replace \n\t from string in javascript replace all linebreaks with &lt;br&gt; js js replace newline javascript replace \r\n\t replace the enter symbol with new line javascript js replace new line with br js replace line breaks replace line break with br javascript replace n in js replace br with newline javascript replace break lines javascript js replace line break wit hnothing replace line break js js replace new line replace r n with br javascript javascript replace line break javascript replace n to br javascript replace line breaks js replace newline character js replace &lt;br/&gt; replace n in javascript js replace n with br js replace break line replace line breaks in string javascript replace n to br javascript replace line breaks with \n js replace \n with new string javascript javascript replace &lt;br/&gt; replace n with newline javascript javascript replace line breaks with space js replace newline with space javascript replace line breaks with br js replace line breaks with br replace new line with br js javascript replace new line with br javascript replace space with line break javascript replace newline replace \n js javascript replace newline with br convert \r\n\r\n to a new line js
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source