1

I am storing array in cookie through jQuery cookie plugin but each time I get it from cookie, it returns empty

I define array as:

var myArray = [];
myArray[ 0 ] = "hello";
myArray[ 1 ] = "world";

Set it in cookie

$.cookie('cookie-array', myArray);

But getting this cookie and printing, prints empty string

console.log($.cookie('cookie-array'));

EDIT: Arrays define in other questions are object arrays no like this array I mentioned here. Also I dont want to user JSON library.

Muhammad Imran Tariq
  • 22,654
  • 47
  • 125
  • 190

1 Answers1

4

Have a look at: https://code.google.com/p/cookies/

to store an array

$.cookie('COOKIE_NAME', escape(myArray.join(',')), {expires:1234});

to get it back

cookie=unescape($.cookie('COOKIE_NAME'))
myArray=cookie.split(',')
Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107