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
CodePudding user response:
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);