Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript localStorage clear items

localStorage.clear();//this clears the localStorage completely
Comment

js localstorage clear

<!DOCTYPE html>
<html>
  <head>
    <style>
      body {
        text-align: center;
      }
      h1 {
        color: green;
      }
    </style>
  </head>
  <body>
    <h2>Create local storage items </h2>
    <button onclick="createItems()">
      Create local storage items
    </button>
    <h2>Display Items</h2>
    <button onclick="displayItems()"> Display items</button>
    <p id="show"></p>
    <h2>Remove Items</h2>
    <button onclick="deleteItems()"> Clear locak storage </button>
    <h2>Display Items Again</h2>
    <button onclick="displayItems()"> Display again </button>
    <p id="demo"></p>
    <script>
      function createItems() {
        // Set item in local storage. 
        localStorage.setItem("Welcome toW3Docs ", " ");
        localStorage.setItem("Storage Clear Method ", " ");
      }
      function deleteItems() {
        // Clear localStorage items 
        localStorage.clear();
      }
      function displayItems() {
        let l, i;
        // Display items 
        document.getElementById("show").innerHTML = "";
        for(i = 0; i < localStorage.length; i++) {
          res = localStorage.key(i);
          document.getElementById("show").innerHTML += res;
        }
      }
    </script>
  </body>
</html>
Comment

js localstorage clear

<!DOCTYPE html>
<html>
  <head>
    <style>
      body {
        text-align: center;
      }
      h1 {
        color: green;
      }
    </style>
  </head>
  <body>
    <h2>Create local storage items </h2>
    <button onclick="createItems()">
      Create local storage items
    </button>
    <h2>Display Items</h2>
    <button onclick="displayItems()"> Display items</button>
    <p id="show"></p>
    <h2>Remove Items</h2>
    <button onclick="deleteItems()"> Clear locak storage </button>
    <h2>Display Items Again</h2>
    <button onclick="displayItems()"> Display again </button>
    <p id="demo"></p>
    <script>
      function createItems() {
        // Set item in local storage. 
        localStorage.setItem("Welcome toW3Docs ", " ");
        localStorage.setItem("Storage Clear Method ", " ");
      }
      function deleteItems() {
        // Clear localStorage items 
        localStorage.clear();
      }
      function displayItems() {
        let l, i;
        // Display items 
        document.getElementById("show").innerHTML = "";
        for(i = 0; i < localStorage.length; i++) {
          res = localStorage.key(i);
          document.getElementById("show").innerHTML += res;
        }
      }
    </script>
  </body>
</html>
Comment

PREVIOUS NEXT
Code Example
Javascript :: add click event listener javascript 
Javascript :: javascript random 4 digit number 
Javascript :: nodejs binary string to decimal number 
Javascript :: axios network error react native 
Javascript :: make multiple function calls at the same time js async 
Javascript :: nodejs remove null from object 
Javascript :: regex expression for password validation form validation 
Javascript :: how to fill array with consecutive numbers javascript 
Javascript :: unsubscribe all youtube channel using javascript 
Javascript :: mongoose find sort 
Javascript :: reverse int js 
Javascript :: cannot get issue in nodejs 
Javascript :: Access to XMLHttpRequest has been blocked by CORS policy 
Javascript :: how to turn number into string javascript 
Javascript :: check local storage javascript 
Javascript :: ion input ios keyboard over 
Javascript :: datatable numbering 
Javascript :: Regular Expression for Detect Iranian Mobile Phone Numbers | IR mobile number Regex Pattern 
Javascript :: app.use public 
Javascript :: javascript number between values 
Javascript :: moment time format by country 
Javascript :: using async in useeffect 
Javascript :: loop through javascript object 
Javascript :: Error: Not implemented: window.alert 
Javascript :: javascript how to reverse a string 
Javascript :: how to create an array in node js 
Javascript :: rounding number to x decimals javascript 
Javascript :: filter out object in array using two arguments 
Javascript :: get Two digit number js 
Javascript :: javascript click on all links 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =