Local Storage Noob
I'm really new to local storage and really confused on how it works. I am trying to have it save user inputs for future use, is there a way to do that with out overwriting the last stored input?
14 Replies
store an array in json format, then when you have to store another value, retrieve the json, turn it back into an array, add the element, then back to json and to localstorage
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
if you google "store array in localstorage" you should get a ton of examples
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I've looked up so much stuff on this and nothing works, do you think you could find something to help me or write something that shows this? My inputs just get overwritten every time.
share your code, and I'll try to have a look later
that's not an array, that's an object
if you share your code in a code block instead of a screenshot, it's much easier to edit and show you changes
if you use a codepen demonstrating the issue, it's even easier 🙂
what is a code block?
if you read the "How To Ask A Good Question" thread pinned to the #front-end channel, it'll explain
in short, you put ```js on one line, paste your code underneath on a new line, and then on a new line at the bottom put ```, and it adds code highlighting and lets people copy/paste and reshare your code if they change anything to fix it
okay
that should work
like I said earlier, you have to fetch the old value, parse it, then add to it and save it again
it works ❤️ thank you so much this was really frustrating me
glad to help 🙂