Javascript Browser Storage getItem() Method with dot notation

Introduction

You can also get the value by using dot notation (obj.key):

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() {//from w ww.  ja  va2  s.c om
  sessionStorage.test1 = "hello";
}

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

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



PreviousNext

Related