Try to use Object.keys(localStorage). When you requested a key:
var arrayOfKeys = Object.keys(localStorage);
Simply! This returns an array of keys. Now if you want the values:
var arrayOfValues = Object.values(localStorage);
It returns an array.
Please note that this Object.valuesis experimental, so the alternative would be:
var arrayOfValues = [];
for(var i in localStorage){
if(localStorage.hasOwnProperty(i)){
arrayOfValues.push(localStorage[i]);
}
}
source
share