10 examples of 'localstorage get all items' in JavaScript

Every line of 'localstorage get all items' 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
101getAllItems() {
102 const items: SimpleStorageItem[] = [];
103
104 for (let i = this.length - 1; i >= 0; i--) {
105 const key = this.storageSource.key(i);
106
107 if (key !== null) {
108 const value = this.getItem(key);
109 items.push({ key, value });
110 }
111 }
112
113 return items;
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

100getAll() {
101 return resolve<StoreInfo[]>(
102 this.storeToJson().map(store => ({
103 hs: new HighlightSource(
104 store.hs.startMeta,
105 store.hs.endMeta,
106 store.hs.text,
107 store.hs.id
108 ),
109 info: store.info
110 }))
111 );
112}
44getItem(key) {
45 return this.data.get(key);
46}
45all(criteria) {
46 this.refresh();
47
48 return this.ids.reduce((records, id) => {
49 const key = util.getKey(this.name, id);
50 const record = util.toJSON(this.storageAdaptor.getItem(key));
51
52 if (!record) {
53 return records;
54 }
55
56 if (criteria) {
57 const match = util.findMatch(criteria, record);
58 if (match) {
59 records.push(record);
60 }
61 }
62 else {
63 records.push(record);
64 }
65
66 return records;
67 }, []);
68}
204function getAll(storageFacility)
205{
206 //Loop through the keys present in storageFacility, inserting in to
207 //dataObjArray objects containing the key-value pair each belongs to
208 var storedItemCount = storageFacility.length;
209 for(; i < storedItemCount; i++)
210 {
211 var currentKey = storageFacility.key(i);
212 var currentValue = (storageType === "globalStorage" ? storageFacility.getItem(currentKey).value : storageFacility.getItem(currentKey));
213 dataObjArray.push({key: currentKey, value: currentValue});
214 }
215 /////
216}
117function getLocalStorageItem(key) {
118 try {
119 return JSON.parse(
120 window.localStorage.getItem(key)
121 );
122 } catch (e) {
123 return null;
124 }
125}
10getItem(key) {
11 return this.store[key] || null;
12}
88protected getAllItems(): Map<string, string> {
89 if (this.cachedCookieString === document.cookie) { // No changes
90 return this.cachedItemsMap;
91 }
92 const map = new Map();
93 if (typeof document === 'undefined') return map;
94 const cookies = document.cookie.split(';');
95
96 for (let i = 0; i < cookies.length; i++) {
97 const cookie = cookies[i].trim();
98 const eqPos = cookie.indexOf('=');
99 const key = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
100 const value = eqPos > -1 ? cookie.substr(eqPos + 1, cookie.length) : cookie;
101 map.set(key, value);
102 }
103 // detect changes and emit events
104 if (this.cachedItemsMap) {
105 map.forEach((value, key) => {
106 let cachedValue = this.cachedItemsMap.get(key);
107 cachedValue = (cachedValue !== undefined) ? cachedValue : null;
108 if (value !== cachedValue) {
109 this.emitEvent(
110 key,
111 WebStorageUtility.getGettable(value),
112 WebStorageUtility.getGettable(cachedValue),
113 );
114 }
115 });
116 this.cachedItemsMap.forEach((value, key) => {
117 if (!map.has(key)) {
118 this.emitEvent(key, null, WebStorageUtility.getGettable(value));
119 }
120 });
121 }
122 this.cachedCookieString = document.cookie;
123 return this.cachedItemsMap = map;
124}
130find({profileId, type}) {
131 return this.rs.encryptic.getAll(`${profileId}/${type}/`);
132}
27public Get(key: string): any {
28 return this.localStorageService.get(key);
29}

Related snippets