I am looking for a way to delete one object in an array, without having to delete all the local storage, like by using local.storage.clear
I tried using Local.storage.removeItem but it didn't work. I also used JSON.stringify to set the item, is there any alternative? Thank you!
<!DOCTYPE html> <html> <body> <p id="demo"></p> <input id="click"type="checkbox" onclick="savelocalstorage()"> </button> <script> var n=0; function savelocalstorage() { var myarray = [ { format: "jpg", name: "Alice" }, { format: "jpg", name: "Jack" }, ]; if (n % 2 == 1) { document.getElementById("click").checked = false; localStorage.removeItem(myarray[0]); } else { document.getElementById("click").checked = true; localStorage["myarray"] = JSON.stringify(myarray[0]); } n++; } </script> </body> </html>
localStorage.removeItem("myarray");localStorage.removeItem('itemName');.