I have created an angular native script project and i am using the "nativescript-localstorage". I want to get all the keys in the storage ,how will i do it
Asked
Active
Viewed 306 times
0
-
Possible duplicate of [How can I show all the localStorage saved variables?](https://stackoverflow.com/questions/5410820/how-can-i-show-all-the-localstorage-saved-variables) – msanford Oct 15 '18 at 13:59
4 Answers
2
You can loop through all the localStorage
items and use the localStorage.key(index)
to get the key and use it in localStorage.getItem
to get the value.
for (let i = 0; i < localStorage.length; i++) {
let key = localStorage.key(i);
let val = localStorage.getItem(key);
}

William Juan
- 1,395
- 1
- 7
- 10
0
You can use localStorage
Creating Entries
let key = 'Item 1';
localStorage.setItem(key, 'Value');
Reading Entries
let myItem = localStorage.getItem(key);
Updating Entries
localStorage.setItem(key, 'New Value');
Deleting Entries
localStorage.removeItem(key);
Clearing Everything
localStorage.clear();

Sunil Singh
- 11,001
- 2
- 27
- 48
0
You need to use localstorage.length that will return you the number of keys stored.
console.log("Keys stored", localStorage.length);
You can also iterate for all the keys stored in localstorage localstorage.key return the key name at this position
for (let i = 0; i < localStorage.length; i++) {
let key = localStorage.key(i); // Will return the name of the key
let val = localStorage.getItem(key); // will return the value
}

Narendra
- 4,514
- 2
- 21
- 38
0
get length of local storage keys. returns number of keys stored
localStorage.length
Return the key name at this position
localStorage.key(id)
let n = localStorage.length;
for(let i=0;i<n;i++){
console.log("--->",localStorage.key(i));
}

D C
- 708
- 1
- 6
- 17