I currently have the following JavaScript:

Code:
// localStorage

localStorage.setItem("distance", distance);
localStorage.setItem("timestamp", timestamp);

if (typeof (Storage) !== "undefined") {
    if (localStorage.getItem("distance") === null || localStorage.getItem("timestamp") === null) {
        document.getElementById("history").innerHTML = "There are currently no records to display.";
    } else {
        document.getElementById("history").innerHTML = "You travelled " + localStorage.getItem("distance") + " miles in " + "on " + localStorage.getItem("timestamp") + ".";
    }
} else {
    document.getElementById("history").innerHTML = "Your browser does not support the localStorage API.";
}
This obtains the "distance" and "timestamp" information and appends it into a sentence.

EXAMPLE
You travelled 3 miles in on 02 April 2013 15:52:36.




However, I want to create a list. I have tried using the localStorage.length and localStorage.key(i) elements, but it does not create a loop. It overwrites my existing localStorage content values.

How can I sort this?