Error with displaying localstorage content
Uncaught TypeError: Cannot read property '0' of null
var sorted_high_scores = get_saved_data();
var table = document.getElementById("highscores");
for (var i = 0; i < 10; i++) {
var item = sorted_high_scores[i];
var row = document.createElement("tr");
var placeCell = document.createElement("td");
var dayCell = document.createElement("td");
var scoreCell = document.createElement("td");
placeCell.appendChild(document.createTextNode(i+1));
dayCell.appendChild(document.createTextNode(ms_to_seconds(item.time).toString(10)));
scoreCell.appendChild(document.createTextNode(item.day));
row.appendChild(placeCell);
row.appendChild(dayCell);
row.appendChild(scoreCell);
table.appendChild(row);
}
Been having this problem for a little while, help is appreciated.
Posted May 17, 2017, 11:04 AM UTC
what's get_saved_data doing?
and the value of the sorted_high_scores variable? or of localStorage.getItem("high_scores")
do you stringify the value that you put into the localStorage?