65
loading...
This website collects cookies to deliver better user experience
key
and value
.window.localStorage.setItem('name', 'Dev Community');
window.sessionStorage.setItem('name', 'Dev Community');
name
is the key and Dev Community
is the value. Also note that local storage and session storage can only store strings.JSON.stringify()
method before storing to setItem.const person = {
name: "Naveen Chandar",
location: "India"
}
window.localStorage.setItem('user',JSON.stringify(person));
window.sessionStorage.setItem('user',JSON.stringify(person));
window.localStorage.getItem('user');
window.sessionStorage.getItem('user');
"{"name":"Naveen Chandar","location":"India"}"
JSON.parse(window.localStorage.getItem('user'));
JSON.parse(window.sessionStorage.getItem('user'));
window.localStorage.removeItem('user');
window.sessionStorage.removeItem('user');
window.localStorage.clear();
window.sessionStorage.clear();
window.localStorage.key(index);
window.sessionStorage.key(index);
window.localStorage.length;
window.sessionStorage.length;
if (typeof(Storage) !== "undefined") {
// Code for localStorage/sessionStorage.
} else {
// Sorry! No Web Storage support..
}