var aa=[1,2,3];
var sStorage=window.sessionStorage;
sStorage.aa=aa;
console.log(sStorage.aa); //輸出1,2,3
function stringToArray(arr){
return arr.split(',');
}
function stringToArray(arr){
var tempArr=arr.split(',');
var returnArr=new Array();
var i,len=tempArr.length;
for(i=0;i<len;i++){
if(typeOf(tempArr[0]*1)==='number'){
returnArr.push(tempArray[i]*1);
}else{
returnArr.push(tempArray[i]);
}
}
return returnArr;
}
/*思路很簡單:JSON對象提供的parse和stringify將其餘數據類型轉化成字符串,再存儲到storage中就能夠了*/
var obj = { Hellow:'world' };
var str = JSON.stringify(obj);
//存入
sessionStorage.obj = str;
//讀取
str = sessionStorage.obj;
//從新轉換爲對象
obj = JSON.parse(str);
var t=[{'a':1},{'a':2}];
t.push({'a':3});//增
t[0].a=11;//改
t.remove(0);//刪
var obj = { Hellow:'world' };
var str = JSON.stringify(obj);
str.a="122";
delete str["a"];//刪除
test = new Array();
test[0] = 'Apple';
test[1] = 'Ball';
test[2] = 'Cat';
test[3] = 'Dog';
//刪除索引未2的元素
alert("Array before removing elements: "+test);
test.splice(2, 1);
alert("Array after removing elements: "+test);