1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 00:29:09 -05:00
denoland-deno/docs/runtime/web_storage_api.md
2021-06-15 15:43:14 -04:00

1.1 KiB

Web Storage API

As of Deno 1.10, the Web Storage API (localStorage & sessionStorage) was introduced, which through localStorage allows persistent storage, whereas sessionStorage is a non-persistent memory-based storage.

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.

Example

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

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

The syntax for reading the localStorage item is as follows:

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

The syntax for removing the localStorage item is as follows:

localStorage.removeItem("myDemo");

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

localStorage.clear();