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

251
Visualizações
How to remove separator icon for last array map?

I have an array of strings that I want to render in a way that's one after the other with arrows in between as separators.

const folders = ["Folder 1", "Folder 2"]

So I tried the following code :

<div style={{display: "flex"}}>
   {folders.map(folder => (
     <p><i className='fa fa-folder'></i> {folder} <i className="fa fa-chevron-right"></i></p>
   ))}
</div>

What this does it put that arrow icon after every folder but i don't want it to put that arrow after the last folder. How do I fix?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

With Array.prototype.map you can have access to the index of item of the array in which you are performing a map

<div style={{display: "flex"}}>
    {folders.map((folder, index) => {
        return (
            <p key={index}>
                <i className='fa fa-folder'></i> 
                {folder} 
                {index !== folders.length - 1 ? <i className="fa fa-chevron-right"></i>: null}
            </p>
         )
        );
    })}
</div>

As you can see I add a line which check if the current index in the map is equal to the length of the folders and if is not the case the closing chevron is display otherwise it is not display.

about 4 years ago · Juan Pablo Isaza Relatório

0

Try:

<div style={{display: "flex"}}>
  {folders.map((folder, key) => (
   <p><i className='fa fa-folder'></i> {folder} 
   {index !== (folders.length - 1) ?  <i className="fa fa-chevron-right"></i> : ''} </p>
 ))}
</div>
about 4 years ago · Juan Pablo Isaza Relatório

0

You can use the index parameter of the map function e.g.

<div style={{display: "flex"}}>
   {folders.map((folder, index) => (
     <p><i className='fa fa-folder'></i> {folder} 
     {index < folders.length -1 && <i className="fa fa-chevron-right"></i>}
</p>
   ))}
</div>
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