Removing items or removing the whole localStorage
We started working with the storage API in the last video in this one we will learn how to remove one item using the removeItem method and how to remove all items using the clear method.
Video Transcript
00:00Welcome back. All right, so we learned about two API options for the local
00:05storage. It's time for us to look at how do we remove an item. Removing an item is
00:09really, really easy. All we have to do to remove an item or reset an item, all that
00:13we have to do is literally just go in our API local storage and then call the
00:18property remove item. Once we call the remove item, all we have to do is just
00:22send what do we want to remove and let's say we want to remove the vis
00:25account because we want the vis account to reset. Once we've done that, we go back
00:30into our browser, we click on refresh and now our data is going to be reset. Next
00:36time when we reload our application, it's going to be as if we came for the first
00:40time or at least it's the first count of our first time. And here we go, we're
00:43back into the first time on our second refresh. Now second way around and by the
00:49way if we had a lot more properties, it's nice to remove one item. The way
00:52you remove many items or all of the items is by calling the local storage
00:57clear. Now the clear function is really, really convenient, especially if you're
01:01doing some sort of a shopping cart or something of that nature and the user
01:04clicks on a reset because they want to start over their shopping cart, a great
01:08idea is to just click on that clear button, enabling the user to start over
01:12from fresh. So by setting the clear method, literally all that's left and let
01:17me do that as the first thing that we do in our application,
01:20basically making everything underneath kind of new making. Let's call
01:30this new each time. Why might you want to do that? You might want to create maybe a
01:34page on your site where whenever you're a student sends you an email or a client
01:39sends you an email saying there's some sort of issue on the site, you could
01:42send them to a page that will automatically clear all their information
01:46and enable you that way to start over if there's some sort of information
01:49that you feel like you need to clear by basically letting the user and sending
01:52information, telling them, hey go to this page, that should help you reset
01:56if you had any issues with your local storage information. Obviously this is
01:59not something you'd want to do on a daily basis, but obviously it's
02:02important to know how to do it now that we set the clear, it should be cleared
02:06and now when we click on refresh it automatically will always be one
02:09because we're always clearing it as the first thing we do. That's it, so
02:13that's all the API options that we really need to be familiar with with
02:16the local storage and the storage object in general. In the next video we're
02:20going to talk a little bit more about a few things you need to know about it.
