Add new line in string in typescript

To add a new line in string in typescript, use new line \n with the + operator it will concatenate the string and return a new string with a new line separator.

let str: string = "";

// add new line
str = "Hi Friends" + "\n";
str = str + "Welcome to Infinitbility";
console.log(str) 

// Output 
// 'Hi Friends
// Welcome to Infinitbility'

put the "\n" where you want to break the line and concatenate another string.

Add br tag in string in typescript

To add br tag in string in typescript, use br tag <br/> with the + operator it will concatenate the string and return a new string with br tag.

let str: string = "";

// add new line
str = "Hi Friends" + "<br/>";
str = str + "Welcome to Infinitbility";
console.log(str) 

// Output 
// 'Hi Friends<br/>Welcome to Infinitbility'

put the "<br/>" where you want to break the line and concatenate another string.

In the console, you will see output something like 'Hi Friends<br/>Welcome to Infinitbility' to see the real output you have to put this string in HTML like the below example.

<div dangerouslySetInnerHTML={{__html: "Hi Friends<br/>Welcome to Infinitbility"}}></div>

I hope it helps you, All the best 👍.