Skip to main content

Command Palette

Search for a command to run...

HTML : LocalStorage and Session Storage

Published
1 min read
S

I love learning about technology and sharing that with others

Introduction

We can save the data i the browser with these two techniques localStorage and SessionStorage

with LocalStorage data will be stored in the browser, even after browser is closed.

with SessionStorage once the browser is closed the data will be lost.

localStorage.setItem("mykey","myvalue");

localStorage.getItem("mykey");
localStorage.getItem("mykey");
localStorage.removeItem("mykey");
localStorage.clear();

SessionStorage

sessionStorage.setItem("mykey","myvalue");
sessionStorage.getItem("mykey");
sessionStorage.removeItem("mykey");
sessionStorage.clear();

var ourArray =[1,2,3,4,5];

localStorage.setItem("ourarraykey",JSON.stringify(ourArray));

sessionStorage.setItem("ourarraykey",JSON.stringify(ourArray));



var storedArray = localStorage.getItem("ourarraykey");
ourArray = JSON.parse(storedArray);

or, for sessionStorage:

var storedArray = sessionStorage.getItem("ourarraykey");
ourArray = JSON.parse(storedArray);

How to use the LocalStorage with JSP

14 views

More from this blog

H

hashcodehub

271 posts

Consistent, Passionate and Organized :)