For those mentioning using Object.keys(localStorage)
... don't because it won't work in Firefox (ironically because Firefox is faithful to the spec). Consider this:
localStorage.setItem("key", "value1")
localStorage.setItem("key2", "value2")
localStorage.setItem("getItem", "value3")
localStorage.setItem("setItem", "value4")
Because key, getItem and setItem are prototypal methods Object.keys(localStorage)
will only return ["key2"]
.
You are best to do something like this:
let t = [];
for (let i = 0; i < localStorage.length; i++) {
t.push(localStorage.key(i));
}