en
Home About project

Remove line breaks with JavaScript

If you need to remove line breaks from text with JavaScript you can use next string method:

  • replace(regexp/substr, newstring)

The replace() method searches for a match between a substring (or regular expression) and a string, and replaces the matched substring with a new substring.

Line breaks in text are generally represented as:

  • \r\n - on a windows computer
  • \r - on an Apple computer
  • \n - on Linux

To remove line breaks using JavaScript see example:

    //Removes all 3 types of line breaks
    Text = Text.replace(/(\r\n|\n|\r)/gm," ");