How To Remove Specific Item From Local Storage Array?
I'm building a 'to do list' , The user appends new notes to the list after clicking . I saved all the appended data in the local storage. Now i want to remove the clicked note fr
Solution 1:
As stated in comments you need to provide only relevant code, but just to clear things out here, the way to go here is:
- To have an empty array of
notes. - Add this array to
localStoragevialocalStorage.setItem("savedNotes", JSON.stringify(notes)). - Every time you add a note you will need to: parse this array back from
localStoragewithnotes = JSON.parse(localStorage.getItem("savedNotes")). - Then push the new
noteinto this array vianotes.push(note). - Then set this item again with
localStorage.setItem("savedNotes", JSON.stringify(notes)), it will update your existing item in the localStorage.
It all relies on Storage.getItem() and Storage.setItem() methods.
And to remove a note from the array you need to do the same thing, expect that you will search for this note in the parsed array and remove it.
Post a Comment for "How To Remove Specific Item From Local Storage Array?"