Table of contents
In this article we will understand how localStorage in js wroks
setItem()
getItem()
removeItem()
What is localStorage in js:
In Google Chrome, web storage data is saved in an SQLite file in a subfolder in the user’s profile. The subfolder is located at \AppData\Local\Google\Chrome\User Data\Default\Local Storage on Windows machines and ~/Library/Application Support/Google/Chrome/Default/Local Storage on macOS. Firefox saves storage objects in an SQLite file called webappsstore.sqlite, which is also located in the user’s profile folder.
In simple terms if you want to access you localstorage data in Chrome you have to click Inspect=> appliaction=>localstorage, Here you will get your data in the key-value pair form .
setItem():
syntax :
localStorage.setItem(keyname, value)
Here we can see the syntax that key-value pair required for setItem property.
also one have to remember that while passing the kay name, the name must in under inverted " " commons as we are representing the key as a string.
getItem():
syntax :
const variable = localStorage.getItem("key name")
Here we have to store the data in a new variable and use the above syntax for get the desired result.
removeItem():
As per name suggest the removeItem() method is used to remove the object which is already stored in localStorage.
syntax :
localStorage.removeItem("key-name").
That's how we can use local storage to store the objects in client server.
if you have any query, feel free to ask.
Happy Learning.