I have been trying to figure out that how to insert list of into array and push new data into same array.
collectionList: [any];
//Array defined
collection: [
{
Name:any,
Code:any,
Location:any,
Capacity:number,
Remaining:number
}
]
// Getting data from database in collection array to push inside arrayList
this.collection=[{
Name:item.Name,
Code:item.Code,
Location:item.Location,
Capacity:item.Capacity,
Remaining:item.Remaining
}]
//Then Pushing data to collectionList
if (item.register== true){
this.collectionList.push(this.collection)
}
collectionListwithout actually initializing it (which would be caught if you compile TS with--strict), so it'sundefinedat runtime, and you can't callpush()on that. Initialize your property (e.g.,collectionList: any[] = []) and try again?