How to get data from localstorage in javascript

Below is an example to get data from localstorage in javascript

<html> 
<head>
<title>Get data from session storage in javascript</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<body>
<h3>Get Data From Local Storage Using Javascript</h3>
<p id="demo" style="font-weight:bold;"></p>
<script type="text/javascript">
localStorage.setItem("username",'My name is XYZ'); document.getElementById("demo").innerHTML = localStorage.getItem("username");
</script>
</body>
</html>
  • localStorage.getItem() is used to get the value of the variable stored on the local storage.

--

--

Hi, This is Biplab and I am web developer well versed in PHP and other open source technologies. I am here to share my experience with the community.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Bipsmedium

Bipsmedium

Hi, This is Biplab and I am web developer well versed in PHP and other open source technologies. I am here to share my experience with the community.