我在本地存储中存储了一个数组(将其解析为 json)。我把它放回到一个对象中,从中删除了一些项目,我需要用本地存储中的新值更新密钥。
var counter = [0,1,2];
var count = counter[0];
var questions = localStorage.getItem('questions');///questions had been stored in local storage with another function
console.log(questions);
questions = $.parseJSON(questions);
if (questions != 0){
$('.question').html(questions[count]['question']);
var options = (questions[count]['options']);
options.forEach(function (item) {
$('.options').html(item);
});
var index = counter.indexOf(1);
questions = questions.splice(index, 1);
console.log(questions);
localStorage.removeItem('questions);
counter = counter.splice(index, 0);
现在,当我从本地存储中删除问题键时,整个问题数组都会被删除,但是,我只需要删除传递的特定问题数组。