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

95
Visualizações
displaying last index arrow issue

I am displaying a values from with arrow like this

ABC--->DES--->FDD--->BGR--->

It's working fine but I don't want to display last arrow because it doesn't make any sense. How can I resolve this?

let network = ['ABC', 'DES', 'FDD', 'BGR'];

for (i = 0; i < network.length; i++) {
  temp = "<span style = 'border:3px dotted #399bff;'>" + network[i] + "</span><bold style = 'color : #d77300;'> <i class='fa fa-long-arrow-right'></i></bold>";
  network[i] = temp;
}

console.log(network.join());

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

0

The issue is because your loop adds the arrow to the end of every item in the array.

To fix the issue you can use map() to wrap each item in a span, and then use join() separately to combine each element in to a single string with the arrow image between them.

In addition, don't put inline styling in your HTML, especially not when that HTML is in your JS. Use a separate stylesheet to apply styling to the content. In addition, there is no <bold /> element in HTML. Use CSS to apply font-weight to the i element instead.

Here's a working example:

let network = ['ABC', 'DES', 'FDD', 'BGR'];
let html = network.map(item => `<span>${item}</span>`);

document.querySelector('#foo').innerHTML = html.join(`<i class="fa fa-long-arrow-right"></i>`);
#foo span {
  border: 3px dotted #399bff;
}

#foo i {
  color: #d77300;
  font-weight: bold;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9YAA1QvwINks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgel0g==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<div id="foo"></div>

about 4 years ago · Juan Pablo Isaza Relatório

0

Display the output normally without the arrow. Check if it not the last index, add the arrow; otherwise; skip the arrow.

for (i=0;i<network.length;i++){
    temp = "<span style = 'border:3px dotted #399bff;'>" + network[i] + "</span>";
    if (i !== network.length-1){
        temp += "<bold style = 'color : #d77300;'> <i class='fa fa-long-arrow-right'></i></bold>"
    }
    network[i] = temp;
}
about 4 years ago · Juan Pablo Isaza Relatório

0

Process the first element. and add subsequent elements with the arrows first.

network=['aaa','bbb','ccc','ddd'];
network[0] = "<span style = 'border:3px dotted #399bff;'>" + network[0];
for (i=1;i<network.length;i++){
    temp ="</span><bold style = 'color : #d77300;'> <i> --></i></bold>"+"<span style = 'border:3px dotted #399bff;'>" + network[i]; 
    network[i] = temp;   
    }
document.write(network);

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