Navigate back to the homepage

how to add new line in string in typescript?

Infinitbility
TypeScript
July 16th, 2022 · 1 min read
how to add new line in string in typescript?

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.

1let str: string = "";
2
3// add new line
4str = "Hi Friends" + "\n";
5str = str + "Welcome to Infinitbility";
6console.log(str)
7
8// Output
9// 'Hi Friends
10// 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.

1let str: string = "";
2
3// add new line
4str = "Hi Friends" + "<br/>";
5str = str + "Welcome to Infinitbility";
6console.log(str)
7
8// Output
9// '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.

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

I hope it helps you, All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

how to add space in string in typescript?

how to add space in string in typescript?

TypeScript, add space in string example with step-by-step guide.

July 16th, 2022 · 1 min read
how to add two numbers in react native?

how to add two numbers in react native?

An example of add two numbers in react native with a step-by-step example.

July 15th, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]