how to access local storage code example

Example 1: javascript clear localstorage

window.localStorage.clear(); //clear all localstorage
window.localStorage.removeItem("my_item_key"); //remove one item

Example 2: how to get variable in local storage in javascript

localStorage.getItem('id');

Example 3: localstorage.getitem()

//The following snippet accesses the current domain's local Storage object 
//and adds a data item to it using Storage.setItem().
localStorage.setItem('myCat', 'Tom');

//The syntax for reading the localStorage item is as follows:
const cat = localStorage.getItem('myCat');

//The syntax for removing the localStorage item is as follows:
localStorage.removeItem('myCat');

//The syntax for removing all the localStorage items is as follows:
localStorage.clear();