Чтобы написать новую строку в JavaScript, вы можете использовать следующие методы:
-
Метод 1. Использование символа новой строки “\n”:
console.log("This is the first line.\nThis is the second line."); -
Метод 2. Использование литералов шаблона (ES6):
console.log(`This is the first line. This is the second line.`); -
Метод 3. Использование тега разрыва строки в HTML:
console.log("This is the first line.<br>This is the second line."); -
Метод 4. Использование метода String.fromCharCode():
console.log("This is the first line." + String.fromCharCode(10) + "This is the second line."); -
Метод 5. Использование метода объединения массива():
console.log(["This is the first line.", "This is the second line."].join('\n'));