Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

88
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda