Do I want to delete a row of data in the localstorage cache?

1. I have a list, and when I swipe to delete it, I get the index, and call localStorage.removeItem (index).. The data in the cache cannot be deleted. Is there something wrong with my writing? I"m going to delete the option to 1 now. What do I do?

Jan.03,2022

The data in

localStorage is a key-value pair

list is its key

if you want to delete list, removeItem ('list')

delete the data inside getItem ('list') get the array and then set it

< hr >
function f(i){
    let list = localStorage.getItem('list');
    list.splice(i, 1);
    localStorage.setItem('list', list);
}

The

upstairs is basically correct, but localStorage can only store strings. A small change based on him

function f(i){
    var list = JSON.parse(localStorage.getItem('list'));
    list.splice(i, 1);
    localStorage.setItem('list', JSON.stringify(list));
}
Menu