Possible Duplicate:
HTML5 local storage sort
I am storing data into a localstorage using HTML5
I need to have it sort in the order I put them in.
Originally, I had them start with Q: and then appended data to it.
I found out taht when I retrieved the data, it did not come out in the same order I entered them in.
I then did someting like 1Q:.., 2Q:.. + ..
but found that it again did not sort in the order I needed them in.
localStorage.getItem(... )
Wondering how I can tell it what sort order to retrieve the data in?
I have the key as such:
1Q:fdf
2Q:dfdf
3Q:dfdf
For the value is is random values.
I as hoping that having the key in a certain order may make it work.
localStorage is a pure key-value store. it doesn’t care for orders or anything other than its key-value pairs, which are always stringified.
if you want to do something fancier you might want to use
indexed dbwhich belongs to the html5 standard now (or theweb sql databasewhich is implemented in some browsers, but was abandoned some time ago) or pass an stringified object which could contain more info, like the value and a possible sort-order.how exactly did you pass the data to localstorage?EDIT to your answer to my question:
you could create an array, containing your sorted values and store it’s stringified representation. You might need to write your own sort-function for that.
then, to retrieve the value, you can do: