Itβs even possible, itβs a waste of resources. For example, you should serialize your data into a single cookie using JSON.
In Javascript, you can encode an array of topics into a JSON string using JSON.stringify :
$.cookie("cookie_name", JSON.stringify(topicsId_array));
Then you can get the data using JSON.parse :
var topicsId_array = JSON.parse($.cookie("cookie_name"));
Remember that you can use the JS push method to add items to the array ( http://www.w3schools.com/jsref/jsref_push.asp ), so you can get the data from the cookie to add a new identifier with a click, and then save it using stringify.
To finish, you have to take care of duplicates. If you do not want to use them when pressing push, you can use https://api.jquery.com/jQuery.unique/ to clear the array or use your own JS function, such as:
function unique(array_source) { var array_destination = []; var found = false; var x, y; for (x=0; x<array_source.length; x++) { found = false; for (y=0; y<array_destination.length; y++) { if (array_source[x] === array_destination[y]) { found = true; break; } } if (!found) { array_destination.push(array_source[x]); } } return array_destination; } var topicsId_array = ['aaa', 'bbb', 'ccc', 'aaa']; topicsId_array = unique(topicsId_array);
And in the end, something like this should work:
var topicsId_array = JSON.parse($.cookie("cookie_name")) topicsId_array.push("your_new_id"); topicsId_array = $.unique(topicsId_array); $.cookie("cookie_name", JSON.stringify(topicsId_array));;
source share