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.