Languages
[Edit]
EN

JavaScript - string newline character

10 points
Created by:
Imaan-Morin
1009

In this short article, we would like to answer what is the newline character symbol in string in JavaScript.

Quick solution:

Use \n as a newline character.

// ONLINE-RUNNER:browser;

const text = '123\n456\n789';  //  \n used as newline character

console.log(text);  // 123
                    // 456
                    // 789

Notes:

  • JavaScript newline character is platform independed,
  • but, when we work on a text recived from the outside (people create content, application exchange data with endpoints), we need to know what newline character was used or use some techniques do deal with that text - check this article or go to See also section in the below.

 

See also

  1. JavaScript - split string by new line character
  2. JavaScript - universal new lines splitting symbol example

  3. JavaScript - \R equivalent in RegEx

Alternative titles

  1. JavaScript - string new line character
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join