Local Storage let us save the data which is stored in the browser even when a user refreshes or closes a page. Let's know more about what is Local Storage in JavaScript.
Local Storage holds 2 - 100MB+ data. Saved all data in string(JSON) format. It is also useful for web interface data. It is also used for offline storage of data.
It has 3 three types of methods
let itemsArray = {
id: "OWUAIJFNSOTEKSMJUFTHDSUQ",
name: "Rahul"
}
localStorage.setItem('items', JSON.stringify(itemsArray));
const data = JSON.parse(localStorage.getItem('items'));
console.log(data);
Note: JSON.parse() is used to covert the contents ofback into something which we can work with later in the data variable.localStorage
When passed a key name, the removeItem() method will remove that key from the storage if it exists. If there is no item associated with the given key, this method will do nothing.
localStorage.removeItem('items');
This method, when invoked, clears the entire storage of all records for that domain. It does not receive any parameters.
localStorage.clear();
😀Thanks For Reading | Happy Coding😎
Previously published at Complete Guide To localStorage