Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

81
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!