Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How i can Remove list of localStorage by localStorage.removeItem?

I want Remove list of localStorage That startsWith=’MYCLIENTCACHE#…’

How Can Remove Items By For Loop?
My code is

        let y= Object.keys(localStorage).filter(key => key.startsWith('MYCLIENTCACHE#'))                
        for (var i = 0; i <= y.length; i++){
          let x=localStorage.key(i)!;   
        localStorage.removeItem(x);
        }

But not Remove All related Item
One Item remains

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Just iterate through the array returned by Object.keys().

let keys = Object.keys(localStorage).filter((key) => key.startsWith('MYCLIENTCACHE#'));
for (const key of keys) localStorage.removeItem(key);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading