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

Every line of 'how to store array of objects 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
69saveObject(key, value) {
70 this.db.insert(this.prefix + key, JSON.stringify(value));
71}
21public setLocalObject(key: string, obj: any): boolean {
22 return this.setObject(this.localStorage, key, obj);
23}
31public setObject(key: string, value: any): void {
32 this.localStorage[key] = JSON.stringify(value);
33}
96_saveLocalStorage(data: any) {
97 store.set(LOCAL_STORAGE_NAME, data);
98}
80function storagePushToSet([key, value]) {
81 log('storagePushToSet', key, value);
82
83 const item = getLocalStorageItem(key);
84 const list = Array.isArray(item) ? item : [];
85
86 if (list.indexOf(value) === -1) {
87 list.push(value);
88 }
89
90 setLocalStorageItem(key, list);
91}
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}
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}
15function writeStorage(value: string): void {
16 localStorage.setItem(key, value);
17
18 updateLocalState(value);
19}
129setLocal(key: string, value: string) {
130 if (this._supportsLocal) {
131 localStorage.setItem(key, value);
132 }
133}
9function setValueToLocal(key, val, storage) {
10 const normalizeVal = typeof val === 'string' ? val : JSON.stringify(val)
11 storage.setItem(key, normalizeVal)
12}

Related snippets