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))
}
I tried but not getting actual result. Is this correct way to push objects into new array
Sample output:
Update the id:1's age 20 to 19 and display the value 19 and also show the same value 19 even after page refresh
you not need to iterate but only
but if you want to add a new data inside you can add on this way: