I am programming a small program that loads a specific localStorage variable. Here’s my code:
function loadInfo(index) {
var div = document.getElementById('report');
if (localStorage.getItem("stardata") != null) {
// read the data saved in localStorage
var data = localStorage.getItem("stardata");
// turn the data from JSON into an array.
var rdata = JSON.parse(data);
// stringify data
var afdata = JSON.stringify(rdata);
var nfdata = rdata[index];
var adfdata = JSON.stringify(nfdata);
var aafdata = JSON.parse(adfdata);
var keys = Object.keys(aafdata);
var fdata = aafdata[keys];
div.innerHTML += fdata;
return;
}
}
This takes in the data and converts it into strings a few times to get just 1 value. But for some reason, whenever I try to get the value for keys, it does not output anything. I am coding this on a school computer so I can’t access the console. Any help?