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.
69 saveObject(key, value) { 70 this.db.insert(this.prefix + key, JSON.stringify(value)); 71 }
21 public setLocalObject(key: string, obj: any): boolean { 22 return this.setObject(this.localStorage, key, obj); 23 }
31 public 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 }
80 function 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 }
54 function 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 }
21 function 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 }
15 function writeStorage(value: string): void { 16 localStorage.setItem(key, value); 17 18 updateLocalState(value); 19 }
129 setLocal(key: string, value: string) { 130 if (this._supportsLocal) { 131 localStorage.setItem(key, value); 132 } 133 }
9 function setValueToLocal(key, val, storage) { 10 const normalizeVal = typeof val === 'string' ? val : JSON.stringify(val) 11 storage.setItem(key, normalizeVal) 12 }