Whenever I set a cookie and I set its value and have its data type to an array. Then I get the cookie's value and it get rid of the square brackets and turn it into a string. Is there a way to keep the array and the square bracket?
function setCookie(cname, cvalue, exdays) {
const d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60));
let expires = "expires="+d.toUTCString();
var expAcc = d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
let name = cname + "=";
let ca = document.cookie.split(';');
for(let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
file = ["gst", (47, 67)]
setCookie("file", file, 365)
let file2 = getCookie("file")
console.log(file2)
all I get is:
gst, 47, 67