我有一个对象在发生某些数据更改时会更新,我需要将之前的数据存储到数组中并在需要时检索它
/* currently i could get 1 data i need multiple data stored to a storage as array*/
get(){
this.storage.get('uploaded').then((data) => {
console.log("get data", JSON.parse(data));
});
}
set(){
var obj = { upload: true,
file: file.audio //this will hold an object which vary when required
}
this.storage.set('uploaded', JSON.stringify( obj ));
}
答案 0 :(得分:2)
您可以使用数组的 push()方法使用新数据更新数组。
var obj = new Array();
obj.push();// use this whenever you have new data
并使用它来访问值
for (var i in obj) {
//access values using obj[i]
}