Reputation: 485
I am currently trying to loop through an array and append id's to my current jquery cookie but cant see to get it working the way I'd like to.
$.cookie('sampleCookie', 'true');
$.cookie.json = true;
var arrayTest=[{id: 'id1', key: 'true'},{id: 'id2', key: 'true'},{id: 'id3', key: 'true'}];
for (var i = arrayTest.length - 1; i >= 0; i--) {
var currentId = arrayTest[i].id;
$.cookie('sampleCookie' + '&' + currentId);
}
This code block doesnt seem to produce the output I am looking for.
I'd like the cookie to look like "true&id1&id2&id3"
Upvotes: 3
Views: 2509
Reputation: 485
Thanks Adeneo,
this worked for me.
$.cookie('sampleCookie', $.cookie('sampleCookie') + '&' + currentId);
Upvotes: 4