Javascript Browser Storage getItem() Method by index syntax

Introduction

You can also get the value like this:

var x = sessionStorage["test1"];

This example demonstrates how you can get the value of a specified session storage item.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="createItem()">Create session storage item</button>
<button onclick="myFunction()">Get the item value</button>

<p id="demo"></p>

<script>

function createItem() {/* w w  w .  j a v a  2s .co  m*/
  sessionStorage.test1 = "hello";
}

function myFunction() {
  var x = sessionStorage["test1"];
  document.getElementById("demo").innerHTML = x;
}

</script>
</body>
</html>



PreviousNext

Related