diff options
author | Yasser A.Idrissi <spookyframework@gmail.com> | 2021-06-15 20:43:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-15 15:43:14 -0400 |
commit | 5bf4a88aa494073abd57838a60e9140062ac4e41 (patch) | |
tree | 07169dc85a8dda0903b166541f17599cdc1ce687 /docs/runtime | |
parent | 984b8bf0c864310bb373a57aad1fea0b002b74fe (diff) |
docs: Add localStorage example (#10973)
Diffstat (limited to 'docs/runtime')
-rw-r--r-- | docs/runtime/web_storage_api.md | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/docs/runtime/web_storage_api.md b/docs/runtime/web_storage_api.md index 05ed8b648..34a119067 100644 --- a/docs/runtime/web_storage_api.md +++ b/docs/runtime/web_storage_api.md @@ -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(); +``` |