[Solved] How can I store a list in Local_Storage?

Hello Thunkers! :tada:


I am making a Notes app.
I want to store every note the user takes in a tiny db / Local Storage.
Certainly, it would be stored as a list.

How can I do this?

I tried some blocks, but they aren’t working -


Any help would be appreciated :smile:

Thanks! :wink:

2 Likes

Each time you are storing, if you use the same key, you are overwriting what was there before.

If you want to append, you need to

  • extract the record using the key
  • add the new note (append to the list)
  • store the updated list back using the same key

The downside is that you need to extract a larger and larger list each time you need to add to it.
A more satisfactory approach would be to use new key each time.
And to have an absolute counter.
Basically, you have a record called “last” (key= “last”), which is initially set to 0.
When you save the note, and assuming you want to use “meow” as key, then instead you use “meow_1” because the value of “last” is 0. You increment “last” by 1, and save it using its key, then append the _1 to the key and use THAT augmented key (“meow_1”) to store the first record.

Next time something needs to be added, you do not need to recover all the previous notes (unless you need to display them) just to add a new one. You get “last” out, check its value (say it is “n”) , know that you therefore have “n” records, and that the next one needs to be save using key = “meow_” + (n+1).

You have all the flexibility (if you need to recover all the past notes, you simply need to run the suffix of the index in a repeat loop to create all the keys) and adding new ones does not require you to get them all out each time, so you gain in performance.

2 Likes

1 Like

Hello,

check it.

%D0%B8%D0%B7%D0%BE%D0%B1%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5

5 Likes

It’s a great Solution! :white_check_mark:

Thanks a lot, @actech!

It’s the same with local storage. But you asked about local storage. If you have a problem with list inside stored variable then use local storage.

1 Like

hayder,

how to call from airtable? i want to call back all information that he saved to other screen.