studentsOld: any[] = [
{ id: 1, name : 'test', age: 20 },
{ id: 2, name : 'sample', age: 21 }
];
studentsNew: any = [];
tmp = 0;
selcatage;
funedit(post) {
this.tmp = post.name
this.selcatage = post.age
}
funsave() {
this.studentsOld.forEach((item, index) => {
var obj;
obj = {
name: item.name,
age: item.age
}
this.studentsNew.push(obj)
this.tmp = 0
this.fundata()
});
console.log(JSON.stringify(this.studentsNew))
}
我试过但没有得到实际结果。这是将对象推入新数组的正确方法吗
样本输出:
将 20 的年龄更新id:1
为 19 并显示值 19 并且即使在页面刷新后也显示相同的值 19