Q:

javascript get local storage

// localStorage for objects, arrays or any data type
var obj = {
	firstName: "Bob",
    lastName: "Jeff",
    age: 13
}
localStorage.setItem("itemname", JSON.stringify(obj)); // Save the obj as string
var item = JSON.parse(localStorage.getItem("itemname")); 
// ^^ Parse string then set `item` as the obj
4
  var Item = localStorage.getItem('youritem');
2

  var x = localStorage.getItem("key"); 
0
JSON.parse(localStorage.getItem('user')).id
0
The read-only localStorage property allows you to access a 
Storage object for the Document's origin; 
the stored data is saved across browser sessions. 
except for "private browsing" or "incognito" session 

Data stored in localStorage is specific to the protocol of the page. 
In particular, data stored by a script on a site accessed 
		with HTTP (e.g., http://example.com) 
is put in a different localStorage object 
  			from the same site accessed with HTTPS (e.g., https://example.com).

The keys and the values are always 
in the UTF-16 DOMString format, 
which uses two bytes per character. 
As with objects, integer keys are automatically converted to strings.
                   
0

New to Communities?

Join the community