I want to save an array of JSONs as a form of a cookie. For example, the array is like below.
[{"name":"Push_up", "values":{"times":35, "date":"Jan 1", "sec":3}},
{"name":"Pull_up", "values":{"times":20, "date":"Mar 4", "sec":6}}]
and this is a function used for storing cookies.
function setCookie(name, value, exp=1){
var date = new Date();
date.setTime(date.getTime() + exp*24*60*60*1000);
document.cookie = name + '=' + value + ';expires=' + date.toUTCString() + ';path=/';
console.log(name + '=' + value + ';expires=' + date.toUTCString() + ';path=/');
}
I tried using Array.toString and save it as a cookie, but it isn't stringified properly so cookie is not successfully saved. How can I solve this problem?