在localStorage中将元素添加到json

时间:2012-04-06 09:35:28

标签: json local-storage

我有:
 localStorage.xxx = JSON.stringify([["something","hello"],["something2","hello2"]]);
如何在xxx等JSON ["something3","hello3"]中添加新数组。

1 个答案:

答案 0 :(得分:2)

你的意思是:


var arr = JSON.parse( localStorage.xxx ) ;
arr.push( ["something3","hello3"] ) ;
localStorage.xxx  = JSON.stringify( arr ) ;