Learning Local Storage in JavaScript..

in GEMS4 years ago

Hello everyone

In the previous posts, we have discussed the basics of javascript. In this post, we are going to discuss another important topic of JavaScript which is Local Storage. Local Storage is one of the most important topic of JavaScript. What it actually does is store our data in the host. Every website has its own local storage.

11.png

For Example let me show you the local storage of google website.

image.png

I have the google .com open and when write the localStorage in the console. it actually prints the data from the google localStorage.

image.png

As you can see some of the numbers and text but this is not our topic. It was to help you understand where and how can we access the localStorage.
Let's just dive into our tutorial.

Here I have a simple HTML file.

image.png

image.png

If I try to print its local storage it will be empty because i just cleared the local Storage before writing this post.

image.png

Now we will store something in the Local Storage with the help of setItem() method.

image.png

Now if I save it and then console log the local storage it will print something like this.

image.png

we can use another method to get just a single item which is getItem(). If I need to get the property of name only then we can just pass it through the parameter of getItem. just like that.

image.png

we can use the ket method to access the properties index wise.

image.png

by using the remove method we can remove a single item

image.png

and with a clear method, we can clear everything.

image.png


I think this much is enough for today. Now if you like the post please upvote and comment if you want to give me some advise
ntitled-1.png

Sort:  

Congratulations @pakgamer! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :

You received more than 2500 upvotes. Your next target is to reach 2750 upvotes.

You can view your badges on your board And compare to others on the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Support the HiveBuzz project. Vote for our proposal!

I have picked your post for my daily hive voting initiative, Keep it up and Hive On!!