Categories
JavaScript Answers

How to force a line break on a JavaScript concatenated string?

Spread the love

Sometimes, we want to force a line break on a JavaScript concatenated string.

In this article, we’ll look at how to force a line break on a JavaScript concatenated string.

How to force a line break on a JavaScript concatenated string?

To force a line break on a JavaScript concatenated string, we add the '\n' string.

For instance, we write

document.getElementById("address_box").value =
  title + "\n" + address + "\n" + address2 + "\n" + address3 + "\n" + address4;

to put a new line between each string variable with '\n'.

And then we set that as the value of the text area with ID address_box.

Conclusion

To force a line break on a JavaScript concatenated string, we add the '\n' string.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.