10 examples of 'storing array in localstorage' in JavaScript

Every line of 'storing array in 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
112saveToLocalStorage(key, value) {
113 localStorage.setItem(key, JSON.stringify(value));
114}
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

129setLocal(key: string, value: string) {
130 if (this._supportsLocal) {
131 localStorage.setItem(key, value);
132 }
133}
1export function saveToLocalStorage(key: string, value: string): void {
2 (window as any).localStorage.setItem(key, value);
3}
5export function saveToLocalStorage (key, value) {
6 window.localStorage.setItem(key, value)
7}
23export function store(key: string, value: any) {
24 const bak = context.getItem(key);
25 context.setItem(key, JSON.stringify(value));
26 return bak;
27}
2export function store(key: string, value: string): void {
3 try {
4 if (window.localStorage) {
5 window.localStorage.setItem(key, value);
6 }
7 }
8 catch (ex) {
9 }
10}
271function store(name, val) {
272 if (typeof (Storage) !== 'undefined') {
273 localStorage.setItem(name, val)
274 } else {
275 window
276 .alert('Please use a modern browser to properly view this template!')
277 }
278}
96_saveLocalStorage(data: any) {
97 store.set(LOCAL_STORAGE_NAME, data);
98}
21function store(key, value, persist) {
22 if ($.exists(value) && $.isObject(value)) {
23 value = "!!stringified!!" + JSON.stringify(value);
24 }
25
26 if (persist) {
27 localStorage.setItem(key,value);
28 } else {
29 sessionStorage.setItem(key, value);
30
31 if ($.exists(localStorage.getItem(key))) {
32 localStorage.removeItem(key);
33 }
34 }
35}
7set(key, value) {
8 localStorage.setItem(key, JSON.stringify(value))
9
10 if (typeof this.observers[key] !== 'undefined') {
11 this.observers[key].dispatch(value)
12 }
13}

Related snippets