DEV Community

Basha
Basha

Posted on

Local storage

What is local storage?

Local Storage is a data storage type of web storage. That allows the JavaScript sites to store and access the data without any expiration date. This means that the data will always be persisted and will not expire. So, data stored in the browser will be available even after closing the browser window. But it will be gone if the user resets his browser or uninstalled it.

How to view the local storage database?

To view you will need to open the developer tools in your browser then click on the arrow at the top and choose application.

Image

Then choose the local storage, then click on the server you want to view, And that's it.

Image

How to add local storage items using js?

You can easily add items using this snippet:

LocalStorage.setitem("key", "value");
Enter fullscreen mode Exit fullscreen mode

And that's it

How to get the value of an item in js?

Const value = LocalStorage.getItem("key");
console.log(value)
Enter fullscreen mode Exit fullscreen mode

How to delete an item?

Localstorage.removeItem('key")
Enter fullscreen mode Exit fullscreen mode

How to clear all the data?

Locastorage.clear()
Enter fullscreen mode Exit fullscreen mode

And that's all, you just learned Local storage:)

Top comments (0)