I am trying to push to an array but it keeps giving me this error:
Uncaught (in promise): TypeError: Cannot read property 'push' of undefined
TypeError: Cannot read property 'push' of undefined
here is the source where I am simply adding to an array. I take the obsevable from the firestore collection and loop through it. Why is it giving me this error when the array of category objects is right there. categories: Category[];
transactions: Observable<Transaction[]>;
categories: Category[];
private organizeData() {
let category: Category;
this.transactions.forEach(v => {
for (let i = 0; i < v.length; i++) {
category = {name: v[i].category, totalSpent: v[i].amount};
this.categories.push(category);
}
});
}