LocalStorage.clear JavaScript Example

LocalStorage.clear(): clears all keys stored in a given LocalStorage object.

This method, when invoked clears the entire storage of all records for that domain. It does not receive any parameters.

Syntax

The syntax for CLEAR all data:
localStorage.clear();

localStorage.clear() Method Example

The following function creates three data entries in local storage and then deletes them by using clear().
function populateStorage() {
  localStorage.setItem('bgcolor', 'red');
  localStorage.setItem('font', 'Helvetica');
  localStorage.setItem('image', 'miGato.png');

  localStorage.clear();
}

Comments