As you know, to take with localStorage only entries whose keys begin with a certain word, you can use the code:

for (i = 0; i < localStorage.length; i++) { var myKey = localStorage.key(i); if(myKey.slice(0,6) === 'myWord') { console.log(myKey); } } 

And how to delete all such records at the same time? I tried this:

 ... if(myKey.slice(0,6) === 'myWord') { localStorage.removeItem(myKey); } 

so:

 ... if(myKey.slice(0,6) === 'myWord') { localStorage.removeItem(localStorage.key(i)); } 

But deletes one by one each time the code is run.

And how to remove everything at once with one run?

  • clear deletes all entries at once - Grundy
  • clear deletes all entries in general, and I only need to delete those that start with a certain word - stckvrw
  • then only delete one by one - Grundy
  • one
    Through for in collect the keys and remove - SanŚ́́́́́́́́́́́́́
  • Yes, exactly, did not guess. It is enough to collect the keys and delete them in a separate cycle. Thank you - stckvrw

0