Hi i want remove an item from local storage. I try this code:
var pos=JSON.parse(JSON.stringify(localStorage.getItem("position_users")));
var storedNames = JSON.parse(localStorage.getItem("user_login_users"));
if(storedNames.length===1){
localStorage.removeItem("user_login_users");
}else if(storedNames.length>1){
storedNames.slice(pos,1);
console.log(storedNames);
localStorage.setItem("user_login_users", JSON.stringify(storedNames));
alert("utente cancellato");
window.open("onlinemoviecatalog.html");
}}
where user_login_users={[name:"jack"surname:"rossi", name:"rosy",surname:"chan"]} and position_users={[0]}.User_login_users and position_users are in JSON. My code don't remove nothing. How can i do?
Read more here: https://stackoverflow.com/questions/65712806/remove-an-item-form-a-position-in-local-storage
Content Attribution
This content was originally published by Elena Rondina at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.