如何在JavaScript中从cookie创建和读取对象数组的值? [{name =“sss”,age =“33”} ,{name =“ll”,age =“22”}]
答案 0 :(得分:1)
你必须" stringify"数组并将字符串存储在cookie中,如:
var myArray = [{name="sss", age="33"} , {name="ll", age="22"}];
var cookieStr = JSON.stringify(myArray);
// Do whatever you want with your cookie
然后你将字符串稍后退出(作为字符串)并解析它:
var cookieStr = ...; // Get it out of the cookie
var myArray = JSON.parse(cookieStr);