Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

86
Views
React.js start a new line after every number

I am fetching a tracklist from my database which has this format :

" 01. Intro 02. Waage 03. Hyänen (feat. Samra) 04. Ich will es bar (feat. Haftbefehl) 05. Am Boden bleiben (feat. Casper & Montez) "

It is one single String. Right now I am simply calling it with :

if (album && album.title) {
    trackList = (
        <div className={'trackList'} style={{ fontSize: 16 }}>
            {album.tracklist}
        </div>
    );
}

and {trackList} in my App. My goal is to style it, so it makes a new line when a new Number starts. Is there an way to achieve this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can split your string to an array by split method and then iterating over array by map method, like this:

if (album && album.tracklist) {
    trackList = (
        <div className={'trackList'} style={{ fontSize: 16 }}>
            {album.tracklist
                .trim()
                .split(/\D(?=\d+\.\s)/g)
                .map((t, i) => (
                    <p key={i}>{t}</p>
                ))}
        </div>
    );
}

instead of <p> tag in the above code, you can use any html tag, to generate your expected result.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!