Skip to content

Commit

Permalink
docs: Add localStorage example (denoland#10973)
Browse files Browse the repository at this point in the history
  • Loading branch information
getspooky committed Jun 15, 2021
1 parent 984b8bf commit 5bf4a88
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions docs/runtime/web_storage_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,33 @@ introduced, which through `localStorage` allows persistent storage, whereas
To use persistent storage, you need to pass the `--location` flag. The location
for persistent storage is listed in `deno info`, and additionally passing the
`--location` will give you the path for the specified origin.

To learn more about the Web Storage APIs, visit the
[MDN page on Web Storage](https://developer.mozilla.org/en-US/docs/Web/API/Storage).

### Example

The following snippet accesses the local storage bucket for the current origin
and adds a data item to it using `setItem()`.

```ts
localStorage.setItem("myDemo", "Deno App");
```

The syntax for reading the localStorage item is as follows:

```ts
const cat = localStorage.getItem("myDemo");
```

The syntax for removing the localStorage item is as follows:

```ts
localStorage.removeItem("myDemo");
```

The syntax for removing all the localStorage items is as follows:

```ts
localStorage.clear();
```

0 comments on commit 5bf4a88

Please sign in to comment.