10 examples of 'localstorage get item' in JavaScript

Every line of 'localstorage get item' 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
44getItem(key) {
45 return this.data.get(key);
46}
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

10getItem(key) {
11 return this.store[key] || null;
12}
117function getLocalStorageItem(key) {
118 try {
119 return JSON.parse(
120 window.localStorage.getItem(key)
121 );
122 } catch (e) {
123 return null;
124 }
125}
57getItem(key) {
58 if (!key || typeof key !== 'string') return null;
59
60 return getStorageSync[this.$_target](key) || null;
61}
84getItem(item: string, defaultResponse?: any) {
85 var result;
86 try {
87 try {
88 result = JSON.parse(this.$window.localStorage.getItem(item)) || defaultResponse || {};
89 } catch (e) {
90 result = this.$window.localStorage.getItem(item) || defaultResponse || {};
91 }
92 } catch (e) {
93 console.log(e);
94 result = defaultResponse || {};
95 }
96 return result;
97}
38function getLocalStorage(key) {
39 return localStorage.getItem(key);
40};
14get(key: string) {
15 try {
16 return localStorage.getItem(key);
17 } catch (err) {
18 console.error(err);
19 return null;
20 }
21}
30getItem (key) {
31 let value = this.storage.getItem(key);
32
33 if (this.options.serialize) {
34 return this._decode(value);
35 }
36
37 return value;
38}
640function localStorageGetItem(key, defaultValue)
641{
642 var result = null;
643 if (!!window.localStorage) {
644 result = localStorage.getItem(key);
645 }
646 if (result === null) {
647 result = defaultValue;
648 }
649 return result;
650}
27getItem(name) {
28 let item = window.localStorage.getItem(name);
29
30 if (typeof item !== 'undefined' && item !== null) {
31 try {
32 item = window.JSON.parse(item);
33 } catch (e) {}
34 }
35
36 return item;
37}

Related snippets