0

I am trying to use the jQuery Cookie Plugin but it doesn't seem to be reading or writing my data:

var cookieArray = [];
cookieArray['test'] = true;
console.log(cookieArray);

$.cookie('testing', cookieArray, { expires: 10 });
console.log($.cookie('testing') + "hi");

The last log is always just "hi" - Fiddle

I was wondering if there was anything I wasn't including or doing correctly

Pete
  • 57,112
  • 28
  • 117
  • 166

1 Answers1

0

You have declare differently for object array to store them i.e {} it will make them as Object , but i used to JSON.stringify the array and save them for better manipulation.

var cookieArray = {};
cookieArray['test'] = true;
console.log(cookieArray);
$.cookie('testing', JSON.stringify(cookieArray), { expires: 10 });
console.log($.cookie('testing') + "hi");

for these way of doing explained here. fiddle

Community
  • 1
  • 1
Sathya Raj
  • 1,079
  • 2
  • 12
  • 30
  • 1
    hahaha, I had just worked out I was declaring the wrong type of array and was about to post my own answer - http://jsfiddle.net/peteng/rfFRV/9/ – Pete Jun 26 '14 at 12:29