The clear() method of the Storage interface, when invoked, clears all stored keys.

Syntax

storage.clear();

Return value

undefined.

Examples

The following function creates three data entries in local storage, then deletes them using clear().

function populateStorage() {
  localStorage.setItem('bgcolor', 'red');
  localStorage.setItem('font', 'Helvetica');
  localStorage.setItem('image', 'miGato.png');

  localStorage.clear();
}

Note: For a real world example, see our Web Storage Demo.

Specifications

Specification Status Comment
HTML Living Standard
The definition of 'Storage.clear' in that specification.
Living Standard  

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support4123.5810.54
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support1818136113.2 ?

See also

Using the Web Storage API

Document Tags and Contributors

Contributors to this page: fscholz, julienv3, AlePerez92, chrisdavidmills, abbycar, teoli, scunliffe
Last updated by: fscholz,