I have a few localStorage keys that look something like this in dev tools -> storage...
panel_1 {"name":"test_name", "item_1":"test_item", "link_1":"test_link"})
...each panel I have has multiple items and links with a number in its name that increases. I am trying to go through each panel and for the panel I want to get the first item and link to display on a web page then keep looping through until there's no more items or links before doing the same with the next panel. At the moment when I try this it says "undefined". How can I get the correct value? Right now my code looks like this...
var total_keys = localStorage.length;
var panels = [];
var key;
var location = $('#panels .wrapper article:first-child()');
for($i = 0; $i < total_keys; $i++) {
key = localStorage.key($i);
if(key.slice(0, 6) === 'panel_') {
panels.push(key);
};
};
var total_panels = panels.length;
for(var $i = 0; $i < total_panels; $i++) {
var panel = JSON.parse(localStorage.getItem(panels[$i]));
var items = function() {
for(var $x = 1; $x <= 5; $x++) {
var item = 'item_'+$x;
alert(panel.item);
};
};
location.after(items);
};