Local storage array find

Hello,
I’m building an inventory checkin app and would like to store an array or upc codes and descriptions in localstorage so the app can show description once the barcode is scanned and not have to run an sql for every scan.
I am able to pull and store the data in localstorage but having difficulty searching and populating the description field using localstorage.find. There’s isn’t any article available that shows how to use localstorage arrays.
Any guidance would be appreciated.

Thanks.

Hi @Rkhan,
It sounds like the hardest part of this feature for your app is already working!
I highly recommend you to check this couple of resources to get comfortable with localStorage:

  1. Mozilla
  2. Telerik post

.find is an array method and will not work on the localStorage object. Furthermore, the values in localStorage must be strings. However, you can use JSON.stringify & JSON.parse to do some data manipulation and organize our localStorage object for easier management.

I hope this helps! :slightly_smiling_face:

text5.setValue(localStorage.values.inventory.DESCRIPTION[localStorage.values.inventory.ProductNumber_str.findIndex((item) => item === textInput3.value)]);

Hi @Rkhan! I apologize for the confusion. Within Retool, we only have access to Retool's localStorage API, which abstracts most of the data parsing and gives as access to .values and .setValue()

Is the JS query you shared above working?

text5.setValue(localStorage.values.inventory.DESCRIPTION[localStorage.values.inventory.ProductNumber_str.findIndex((item) => item === textInput3.value)]);

If not, what is the current issue we are running into?. I'm happy to help! :slightly_smiling_face: