/
index.md
55 lines (36 loc) · 1.02 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
---
title: "Storage: clear() method"
short-title: clear()
slug: Web/API/Storage/clear
page-type: web-api-instance-method
browser-compat: api.Storage.clear
---
{{APIRef("Web Storage API")}}
The **`clear()`** method of the {{domxref("Storage")}}
interface clears all keys stored in a given `Storage` object.
## Syntax
```js-nolint
clear()
```
### Parameters
None.
### Return value
None ({{jsxref("undefined")}}).
## Examples
The following function creates three data entries in local storage, and then deletes
them by using `clear()`.
```js
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](https://mdn.github.io/dom-examples/web-storage/).
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
[Using the Web Storage API](/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API)