我有一個數組存儲(解析爲json)在localstorage中。 我把它帶回到一個對象中,從中刪除了一些項目,我需要用本地存儲中的新值更新密鑰。從本地存儲中刪除數組項目
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);
現在,當我刪除從本地存儲問題的關鍵,整個問題陣列被刪除,但是,我只需要刪除已傳遞的特定問題陣列。