Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
168
rated 0 times [  175] [ 7]  / answers: 1 / hits: 81519  / 14 Years ago, sat, june 5, 2010, 12:00:00

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?


More From » jquery

 Answers
32

JSON encode it, 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/object.



Example - store array in a cookie:



var arr = ['foo', 'bar', 'baz'];
var json_str = JSON.stringify(arr);
createCookie('mycookie', json_str);


Later on, to retrieve the cookie's contents as an array:



var json_str = getCookie('mycookie');
var arr = JSON.parse(json_str);


Note: cookie functions are not native, taken from How do I create and read a value from cookie?


[#96577] Wednesday, June 2, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lucianom

Total Points: 601
Total Questions: 98
Total Answers: 109

Location: Kenya
Member since Fri, Dec 23, 2022
1 Year ago
lucianom questions
Tue, Feb 22, 22, 00:00, 2 Years ago
Wed, May 5, 21, 00:00, 3 Years ago
Sun, Jan 24, 21, 00:00, 3 Years ago
Sat, Aug 15, 20, 00:00, 4 Years ago
Mon, Jun 22, 20, 00:00, 4 Years ago
;