10 examples of 'how to store array in localstorage' in JavaScript

Every line of 'how to store 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
96_saveLocalStorage(data: any) {
97 store.set(LOCAL_STORAGE_NAME, data);
98}
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

69saveObject(key, value) {
70 this.db.insert(this.prefix + key, JSON.stringify(value));
71}
112saveToLocalStorage(key, value) {
113 localStorage.setItem(key, JSON.stringify(value));
114}
23export function store(key: string, value: any) {
24 const bak = context.getItem(key);
25 context.setItem(key, JSON.stringify(value));
26 return bak;
27}
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}
129setLocal(key: string, value: string) {
130 if (this._supportsLocal) {
131 localStorage.setItem(key, value);
132 }
133}
54function store(storage, key, value) {
55 if (!storage) { throw new Error("Storage object is undefined"); }
56
57 // get
58 if (value === undefined) {
59 var item = storage.getItem(key);
60 return item && JSON.parse(item);
61 // set
62 } else {
63 try {
64 storage.setItem(key, JSON.stringify(value));
65 } catch (err) {
66 // prevent catching old values
67 storage.removeItem(key);
68 }
69 }
70}
9function setValueToLocal(key, val, storage) {
10 const normalizeVal = typeof val === 'string' ? val : JSON.stringify(val)
11 storage.setItem(key, normalizeVal)
12}
15function writeStorage(value: string): void {
16 localStorage.setItem(key, value);
17
18 updateLocalState(value);
19}

Related snippets