我有一个像这样的数组:
var data = {"result":"success","ids":["00000","54321","123","22222","11111","55555","33333","abc123","123abc","12345","44444"]}
localStorage.ids = data.ids;
但现在我这样做了:
angular.forEach(localStorage.ids, function(id, key) {
console.log(id);
});
我想:
0
0
0
0
0
,
5
4
3
等等。
当我console.log(JSON.stringify(localStorage.ids));
时,我得到了:
"00000,54321,123,22222,11111,55555,33333,abc123,123abc,12345,44444"
有谁知道为什么会这样?
答案 0 :(得分:1)
localStorage只存储字符串。
localStorage.setItem('ids', JSON.stringify(data.ids)); // to save
var ids = JSON.parse(localStorage.getItem('ids')); // to get