HTML DOM Storage setItem() method

HTMLWeb DevelopmentFront End Technology

The HTML DOM Storage setItem() method is used for removing a storage object item by passing a given key name.


Following is the syntax for Storage removeItem() method −



sessionStorage.removeItem(keyname,value );

Here, keyname is of type string and represents the key name used for getting the value. The second parameter value represents the new value that will replace the old value.


Let us look at the example for the Storage setItem() method −

Live Demo

<!DOCTYPE html>
<h1 style="text-align:center">Storage setItem() method example</h1>
<p>Create the localstorage item by clicking the below button</p>
<button onclick="itemCreate()">CREATE</button>
<p>Display the localstorage item by clicking the below button</p>
<button onclick="itemShow()">DISPLAY</button>
<p id="Sample"></p>
   function itemCreate() {
      localStorage.setItem("TEXT1","HELLO WORLD");
      document.getElementById("Sample").innerHTML ="The key-value pair has been created";
   function itemShow() {
      var s = localStorage.getItem("TEXT1");
      document.getElementById("Sample").innerHTML ="The 'TEXT1' key value is "+s;


This will produce the following output −

On clicking the CREATE button −

On clicking the DISPLAY button −

Updated on 19-Feb-2021 05:16:28