When working with Angular, I encountered an issue where I received the error message "cannot read property 'fruits' of undefined." Within my class definition, I have included the following:
export class MyClass implements OnInit {
fruits: any[];
doSomething() {
this.myArray.forEach(function(m) {
const my = { test: true };
this.fruits.push(my);
}
}
Since I am considering adding different types to my array, I refrained from defining an interface. What could be causing this problem?