二维数组保存到cookie后再读取
var heartsArray = [[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0]]; //将二维数组编码 var hearts = escape(JSON.stringify(heartsArray)); //保存到cookie setHeartsToCookie(hearts); setTimeout(function() { //从cookie中获取 var val = getHeartsFromCookie("HeartsCookie"); //解码为数组的字符串 var newStr = unescape(unescape(val)); //将字符串转为二维数组 var newArray = eval(newStr); },1000); function setHeartsToCookie(hearts) { setCookie("HeartsCookie",hearts,"d1"); } function getHeartsFromCookie(cookieName) { return getCookie(cookieName); }