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

86
Visualizações
localstorage key numbering breaks when removing an item

Don't worry about how it got to be like this, but this is how my localstorage looks:

enter image description here

This is how it should look:

enter image description here

this is how my loop looks:

for(let i=0;i<localStorage.length;i++){
//I do something cool
}

Now imagine that the same numbering error is happening to say 15 values. How can I change either the key column in localstorage so that it starts at 0 and indents by 1 for every value, or my loop so that it runs from the first key to the last key.

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

0

The localStorage works with key and values. You can loop through it like an javascript object.

for (const [key, value] of Object.entries(localStorage)) {

}

about 4 years ago · Juan Pablo Isaza Relatório

0

You can catch all keys in an array then use that array in your code.

    const lsKeys = Object.keys(localStorage);
    for(let i = 0; i < lsKeys.length; i++) console.log(localStorage[lsKeys[i]]);
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