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

142
Visualizações
Using Array.pop and Array.indexOf togther are not working

I'm trying to use Array.pop(Array.indexOf(value)) but it delete the last element in the index even if the value of that index is not same as I set it, can you please help me

  CheckBoxHandler1(e) {
    console.log(e.target.checked, e.target.name);
    let temp = [...this.state.boxes];
    e.target.checked === true
      ? temp.push(e.target.name)
      : temp.pop(temp.indexOf(e.target.name));
    this.setState({
      boxes: temp,
    });
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It happens because Array.prototype.pop() always remove the last element of the array.

If you want to remove one specific element, you need to do the following:

temp.splice(temp.indexOf(e.target.name), 1);
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