Storage

Local Storage
  • LocalStorage is a type of web storage that allows web applications to store key-value pairs in a client's web browser.
  • Data stored in localStorage persists even after the browser window is closed or the user navigates away from the site.
Set the value in Local Storage
localStorage.setItem("key", "value");
Get the value from Local Storage
localStorage.getItem("key");
Clearing Local Storage
localStorage.clear("key");
  • For use of Local Storage in your component.Follow below step of example code:

Example

//set value in localStorage
localStorage.setItem('username', 'JohnDoe');

// Get value from localStorage
var username = localStorage.getItem('username');

// clear value of localStorage
localStorage.clear();
Session Storage
  • Session Storage is a type of web storage that allows web applications to store key-value pairs in a client's web browser.
  • Data stored in session storage is cleared when the browser tab is closed or the session ends.
Set the value in Session Storage
sessionStorage.setItem("key", "value");
Get the value from Session Storage
sessionStorage.getItem("key");
Clearing Session Storage
sessionStorage.clear("key");
  • For use of Session Storage in your component.Follow below step of example code:

Example

//set value in sessionStorage
sessionStorage.setItem('username', 'JohnDoe');
            
// Get value from sessionStorage
var username = sessionStorage.getItem('username');
            
// clear value of sessionStorage
sessionStorage.clear();
None
  • The first one does not store any data in storage.
  • It is used for existing default data.