Will Boardman
Will Boardman

Reputation: 7

Removing from local storage

I have added to my local storage to create a favorites section on an app i am not trying to remove using a different button. The remove wont work any ideas why?

//Add Favorites
$('.favoritesbtn').click(function() {
        var storedbar = JSON.parse(localStorage.getItem('storedBar'));
        var favArray = [];
        favArray.push(storedbar.id, storedbar.barname, storedbar.address, storedbar.description, storedbar.image);
        localStorage.setItem('favourites', JSON.stringify(favArray));
        console.log(localStorage.getItem('favourites'));

});

//Removing favorites
$('.removebtn').click(function () {                
                localStorage.removeItem('favorties', JSON.stringify(favArray));
            });

Upvotes: 0

Views: 39

Answers (1)

mehulmpt
mehulmpt

Reputation: 16567

You just have to pass the key of the item to remove:

localStorage.removeItem('favorties');

Upvotes: 1

Related Questions