Storing arrays in localstorage
I'm building an app with Appery.io. It's basically a search app that returns results and then you can click into the results to see details.
Results are returned from a REST api in JSON format, and each results has a number of different items in it, including one that is a JSON array which contains multiple sets of three name/value pairs.
I need the array associated with each result to be available in the details page for that result. I don't want to simply run the search again in the details page, because it is a relatively lengthy process and would slow down the entire app.
I'm aware of using JSON.stringify() to make the array a string, and then storing each array in local storage. However, when I do that in Appery.io, it seems that I either a) just save the first result of the array, or b) am doing it wrong.
Can any provide any insight into how I can go about doing this? Happy to provide code, clarify my question, etc.
If there's some problem using JSON.stringify() with Appery.io, try the approach storing them as comma-separated string (unless you're having commas in values):
> ["foo", "bar"].join(); >> "foo,bar"
And them returning them:
> "foo,bar".split(","); >> ["foo, "bar"]
Of course, if you're having commas in values, you can use explicitly specified separator for values, like:
> ["foo,bar", "foz,baz"].join("#"); >> "foo,bar#foz,baz"