我有一个对象,当发生某些数据更改时,该对象就会更新,我需要将先前的和更新的数据存储到数组中,并在需要时检索它
/* 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 ));
}
最佳答案
您可以使用数组的 push() 方法用新数据更新数组。
var obj = new Array();
obj.push();// use this whenever you have new data
并使用它来访问值
for (var i in obj) {
//access values using obj[i]
}
关于angular - 使用新对象更新数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42523804/