jcho0627
1/23/2019 - 7:06 AM

[JS] Loop and Delete from Local Storage

// Delete Bookmark
function deleteBookmark(url) {
    // Get bookmark from local storage
    var bookmarks = JSON.parse(localStorage.getItem('bookmarks'));
    // Loop through bookmarks
    for(i = 0; i < bookmarks.length; i++) {
        if(bookmarks[i].url === url) {
            // Remove from array
            bookmarks.splice(i, 1);
        }
    }
    // Re-set to local Storage
    localStorage.setItem('bookmarks', JSON.stringify(bookmarks));

    // Re-fetch bookmarks
    fetchBookmarks();
}