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

117
Vistas
attribution issues involving for loops

I am trying to remove items from an array. But i have to do it from each item from it. For that, I used a for loop, and ,in the begging of the loop, I try to renovate the array values by using the const seq.

But the sequence array keeps decreasing it's length as the for loop runs. I am trying to remove one item, do some stuff and put it back to the array so I can do the same thing with the next item.

const q = sequence;
for(let i= sequence.length-1; i>=0 ; i--){
        sequence = q;
        sequence.splice(i,1,);
        console.log(sequence);   
           //do some other stuff here

}

output ex:

Input:sequence: [1, 3, 2]

Console Output:[ 1, 3 ]
               [ 1 ]
               []

what i expected: [1, 3]
                 [1, 2]
                 [3,2]
about 4 years ago · Juan Pablo Isaza
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