views:

55

answers:

2

Is it possible , I have a some sort of list and I want to store it on browser , If it is not possible , what is the efficient way of doing this ?

+2  A: 

One quick method is to join() your array into a single string, using an appropriate delimiter:

var a = [1, 2, 3, 4];
a.join('|');  // Returns: "1|2|3|4"

Then simply use the string split() method to get the array back from the cookie string.

Daniel Vassallo
+1  A: 

Serialize it using the JSON notation with some JSON encoder, effectively producing a string like "{name:'myname',age:'myage'}" which you put in a cookie, retrieve when needed and decode back into a JavaScript array.

Search for "javascript json" on Google.

timeNomad
+1 for retaining the keys along with the values.
Jan Kuboschek