Alright, so here's the scenario:
var inventory = ["axe", "shield", "bow", "staff"];
I decided to convert this array into a string and store it in my localStorage.
localStorage.setItem("inventory", JSON.stringify(inventory));
Then I implemented a function that updates the value at a specific index of an element in the passed variable with an empty string. I did this so I could have a way to verify if a particular item was previously stored at a certain index. The value is removed but the index remains for future reference.
function updateInventory(item) {
var updatedItems = JSON.parse(localStorage.getItem("inventory")); //fetching original array
var idx = updatedItems.indexOf(item);
if (idx > -1) {
updatedItems[idx] = ""; //updating new array
localStorage.setItem("inventory", JSON.stringify(updatedItems)); //changes not saved
}
}
Unfortunately, the modified array doesn't get stored back into localStorage as expected.