Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
November 14, 2022 07:38 pm GMT

Basic info of Web storage API/localStorage/sessonStorage

Web storage API:
API allows us to store, read, update and delete data in the browser.
Web storage API has two items-

  • localStorage.
  • sessionStorage.

localStorage data: localStorage is used to keep data permanent. The data never gets lost even in localStorage if the browser is closed. For which developers in most cases use local storage.

Image description

Explanation of this code: We already know that localStorage permanently stores the value. setItem stores or sets the value. Or username is a key value and Nimki is a value. We have to just remember this one is key or the value must be a string.

Image description

This is set in the browser. It creates keys or values.

Now, need to get the values from the console.

Image description

Image description

If need to update the values then need to change only the keys or values only, other codes are the same.

Image description

Image description

set or update both are similar codes and also get. So now, need to know how to remove this from local storage-

Image description

Many times developers need to pass an array and object and then minor changes to the code are required.

Image description

Image description

here is only added JSON.stringify but the other codes are similar. Here most important thing is, Only JSON.stringify is needed when passing arrays and objects to local storage. But it needs to be JSON.parse in the case of gate items.

Image description

Image description

sessionStorage: It works session-wise. sessionStorage works the same as localStorage but the deferent is- if the browser is closed the data will be lost in sessionStorage.


Original Link: https://dev.to/farhanacsebd/basic-info-of-web-storage-apilocalstoragesessonstorage-50i2

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To