Issue
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
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);
Answered By - Chris Hamilton
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.