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

76
Visualizações
remove element from array without reindex

I have this code to add elements to an array and remove one element.

var test = []

test.push({
    bezeichnung: "test_1"
});
test.push({
    bezeichnung: "test_2"
});
test.push({
    bezeichnung: "test_3"
});



// Element aus Array entfernen
test.splice(1, 1);
console.log(test)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

My console log:

Array [ {…}, {…} ]

0: Object { bezeichnung: "test_1" }
1: Object { bezeichnung: "test_2" } // was removed
1: Object { bezeichnung: "test_3" }

But how can I realize, that the "key" from test 3 will not changed? It should be 2 instead 1. Is there a way?

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

0

You can use the keyword delete instead of splice

var test = []

test.push({
    bezeichnung: "test_1"
});
test.push({
    bezeichnung: "test_2"
});
test.push({
    bezeichnung: "test_3"
});



// Element aus Array entfernen
delete test[1];
console.log(test)

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