3

I have a doubt of how do I add a line breaker in a js string . The below is the code :

{ "id": 7, "last": 1, "name": "Customer received Email to change the password/Received. And code that customer  hasn’t requested" }, 

I want a line break after password/Received. I want the desired output as

Customer received Email to change the password/Received. And code that customer hasn’t requested 
3
  • 2
    Depends on where you want to output this. Is it on a webpage or any other location? Commented Oct 16, 2018 at 9:17
  • use \n in the string Commented Oct 16, 2018 at 9:18
  • Hi, welcome to SO. Please take the time to read the tour and also How to Ask. You have received a couple of comments requesting more information. Please update the question to answer those questions so you can receive the answer you are looking for. Commented Oct 16, 2018 at 9:25

2 Answers 2

1

If you want to add the line break and cannot modify the origin of the text, then you could do something like this:

str = "Customer received Email to change the password/Received. And code that customer hasn’t requested"; str.replace("password/Received. ","password/Received.\n"); 

Replace \n with <br/> if you want to output this in HTML.

Sign up to request clarification or add additional context in comments.

2 Comments

I got it . Thank you. I have an other doubt with the same example , How do i add a link in the string. " this is a sample text click here to go to a website " . How do i add a link to the string " click here " ?
str = "this is a sample text click here to go to a website"; str.replace("click here", "<a href='link-to-website.com'>click here</a>"); you mean like this?
0

Depending on where you want to output the string you need other newline options.

If you want to output this on a webpage or in an email, you can use a <br /> tag.

"Customer received Email to change the password/Received.<br />And code that customer hasn’t requested" 

If you want to output this in an alert or in a console, you can use \n.

"Customer received Email to change the password/Received.\nAnd code that customer hasn’t requested" 

1 Comment

I have an other doubt with the same example , How do i add a link in the string. " this is a sample text click here to go to a website " . How do i add a link to the string " click here " ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.