Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I show all the localStorage saved variables?

I want to acess all the localStorage variables saved on a specific page. How do I do that? I want to show it like I would show an array with the join() function

like image 399
Ariel Avatar asked Mar 23 '11 19:03

Ariel


People also ask

How do I display local storage data in HTML table?

You can retrieve the data from localStorage using localStorage. getItem function. Once you have the data, iterate through the cart attribute, and use javascript template strings to create the html structure.


3 Answers

You could try iterating through all of the items in the localStorage object:

for (var i = 0; i < localStorage.length; i++){
    // do something with localStorage.getItem(localStorage.key(i));
}
like image 100
Greg Avatar answered Oct 14 '22 05:10

Greg


I use this block of code frequently:

var i;

console.log("local storage");
for (i = 0; i < localStorage.length; i++)   {
    console.log(localStorage.key(i) + "=[" + localStorage.getItem(localStorage.key(i)) + "]");
}

console.log("session storage");
for (i = 0; i < sessionStorage.length; i++) {
    console.log(sessionStorage.key(i) + "=[" + sessionStorage.getItem(sessionStorage.key(i)) + "]");
}
like image 39
Mark Avatar answered Oct 14 '22 05:10

Mark


Console log the localStorage. It's very simple.

console.log(localStorage);
like image 17
Ananta Prasad Avatar answered Oct 14 '22 04:10

Ananta Prasad