10 examples of 'remove localstorage' in JavaScript

Every line of 'remove localstorage' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
70function remove() {
71 set(null);
72 if (typeof localStorage === "undefined") {
73 return false;
74 }
75 localStorage.removeItem(key);
76}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

70clearLocalStorageList () {
71 if (window.localStorage) {
72 try {
73 localStorage.clear();
74 } catch (e) {
75 alert('localStorage.clear() fail.');
76 }
77 }
78}
104clearLocalStorageList() {
105 if (!!window.localStorage) {
106 try {
107 localStorage.clear();
108 } catch (e) {
109 alert('localStorage.clear() fail.');
110 }
111 }
112}
178public clearLocalStorage(): void {
179 localStorage.clear();
180}
125public clearLocalStorage(): void {
126 this.clearStorage(this.localStorage);
127}
111function clearLocalStorage() {
112 /* Remove all items which have expired. */
113 for (let ii = 0; ii < localStorage.length; ii++) {
114 const key = localStorage.key(ii);
115 const {user, repo} = parseTimeKey(key);
116 if (user && repo) {
117 const timeMs = mbStrToMs(localStorage.getItem(key));
118
119 if (timeMs) {
120 if (isExpired(timeMs)) {
121 removeFromLocalStorage(makeRemoteDataKey(user, repo));
122 removeFromLocalStorage(makeSelfDataKey(user, repo));
123 removeFromLocalStorage(makeTimeKey(user, repo));
124 }
125 } else {
126 console.warn(_logName,
127 'Unable to parse time: ',
128 localStorage.getItem(key));
129 }
130 }
131 }
132}
48remove(key) {
49 this.localStorage.removeItem(key);
50}
140function removeFromLocalStorage(key) {
141 if (DEBUG) {
142 console.log(_logName,
143 'Removing key: ', key);
144 }
145 localStorage.removeItem(key);
146}
73remove() {
74 // cookie存储时,移除二级域以及子域下的cookie,此时参数有两个
75 this.storage.remove(this.name, false);
76 this.storage.remove(this.name, true);
77}
15remove(key) {
16 this.instance.removeItem(key);
17 return this;
18}

Related snippets