×

Save Your Code

If you click the save button, your code will be saved, and you get an URL you can share with others.

By clicking the "Save" button you agree to our terms and conditions.

Report Error

×

Save to Google Drive

If you have a Google account, you can save this code to your Google Drive.

Google will ask you to confirm Google Drive access.

×

Open from Google Drive

If you have saved a file to Google Drive, you can open it here:

Result Size: 625 x 571
x
 
<!DOCTYPE html>
<html>
<body>
<h1>The Storage Object</h1>
<p>This example demonstrates how to loop through all the local storage items for this domain.</p>
<h2>Missing localStorage items?</h2>
<p>Since you might not have any items stored in your local storage, we have added a script that creates some for you.</p>
<button onclick="createItems()">Create local storage items</button>
<h2>Display Items</h2>
<p>Click the button to display all items:</p>
<button onclick="displayItems()">Display items</button>
<p id="demo"></p>
<script>
function createItems() {
  localStorage.setItem("mytime", Date.now());
  localStorage.setItem("myname", "John");
  localStorage.setItem("myage", 36);
}
function displayItems() {
  var l, i;
  document.getElementById("demo").innerHTML = "";
  for (i = 0; i < localStorage.length; i++) {
  x = localStorage.key(i);
  document.getElementById("demo").innerHTML += x + "<br>";
  }
}
</script>
</body>
<!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_storage_loop by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 05 Jun 2019 14:06:52 GMT -->
</html>
×

Report a Problem: