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

118
Visualizações
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 à 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