Javascript Browser Storage removeItem() Method

Introduction

Remove the the specified local storage item:

localStorage.removeItem("mytime");

This example demonstrates how to use the removeItem() method to delete a specified local storage item.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="createItem()">Create local storage item</button>
<button onclick="deleteItem()">Delete item</button>
<button onclick="displayItem()">Display item</button>

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

function createItem() {/*www  .j  a  v a2s  .co m*/
  localStorage.mytime = Date.now();
}

function deleteItem() {
  localStorage.removeItem("mytime");
}

function displayItem() {
  var x = localStorage.getItem("mytime");
  document.getElementById("demo").innerHTML = x;
}

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

The removeItem() method removes the specified Storage Object item.

The removeItem() method belongs to the Storage Object, which can be either a localStorage object or a sessionStorrage object.

removeItem(keyname);

Parameter Values

Parameter Description
keyname Required. A String specifying the name of the item you want to remove

The removeItem() method has No return value.




PreviousNext

Related