Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to split a line into paragraphs JS?

I have a string that is passed through props. It may consist of several sentences. Can I implement splitting this line inside one tag? Maybe through replace ? The end always – (.). I`m using React

const name = "It is just text 1. It is just text 2. It is just text 3."

<p>{name}</p>

I would like to get –

It is just text 1.
It is just text 2.
It is just text 3.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Easiest way to do this is to split the string into an array based on . as the delimeter.

name.split(".").map(p => <p>{p}.</p>);

Assuming you’re using React.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading