This is my following code:
private convertFormat(src: Array<any>): void {
for (let i of src) {
this.selectedMonths.push({
id: i,
itemName: i
})
};
this.selectedMonths = JSON.parse(JSON.stringify(this.selectedMonths));
console.log(this.selectedMonths);
}
However the ".push()
" for when I try to push into the already declared Array<{}>, it gives me this error.
Unhandled Promise rejection: Cannot read property 'push' of undefined ; Zone: ; Task: Promise.then ; Value: TypeError: Cannot read property 'push' of undefined
selectedMonths : any[] = []
at the component class orngOnInit
this.selectedMonths = [];
– DrNioselectedMonths = new Array<{}>()
. – ConnorsFan