使用javascript在Cookie中创建数组 [英] Create array in cookie with javascript
问题描述
是否可以使用数组创建cookie?
我想存储 正如你可以在这个主题: 您结合使用 jQuery.cookie 插件和 JSON 并解决您的问题。 当您要存储数组时,可以在JS中创建一个数组,并使用 当你想要在cookie中找回数组时,使用 Is it possible to create a cookie using arrays? I would like to store As you can read in this topic: You combine the use jQuery.cookie plugin and JSON and solve your problem. When you want to store an array, you create an array in JS and use When you want to retrive the array inside the cookie, you use
这篇关于使用javascript在Cookie中创建数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! a [0] ='peter'
, a ['1'] ='esther'
, a ['2'] ='john'$ c $
JSON.stringify
$。cookie('name','array_string')
var myAry = [1,2,3];
$ .cookie('name',JSON.stringify(myAry));
$。 cookie('name')
来检索cookie值,并使用 JSON.parse
从字符串中取出数组。
var storedAry = JSON.parse($。cookie('name'));
// storedAry - > [1,2,3]
a[0]='peter'
, a['1']='esther'
, a['2']='john'
in a cookie in JavaScript.JSON.stringify
to transform it into an string and stored with $.cookie('name', 'array_string')
var myAry = [1, 2, 3];
$.cookie('name', JSON.stringify(myAry));
$.cookie('name')
to retrive the cookie value and use JSON.parse
to retrive the array from the string.var storedAry = JSON.parse($.cookie('name'));
//storedAry -> [1, 2, 3]