Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

89
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda