FOR in localstorage does not work

0

Good night guys,

The status of my LOCALSTORAGE looks like this:

WhenItrytodothis:

for(varpostin$window.localStorage){console.log(post);varvalue=JSON.parse($window.localStorage[post]);alert(value);response.push(value)}

IttakesupthelengthattributethatalreadycomeswiththestorageandattributekeythatIdonotknowwhereitcamefrom.

    
asked by anonymous 26.09.2018 / 03:10

1 answer

2

Before the loop you need to convert to JSON using the localStorage name with .getItem :

var json = JSON.parse(window.localStorage.getItem('cadeira-maia'));

Within the loop you get the values of each item:

var json = JSON.parse(window.localStorage.getItem('cadeira-maia'));
for (var post in json) {
   console.log(post);
   alert(json[post]);
   response.push(value)
}
    
26.09.2018 / 04:43