I am facing issues with initializing the "categorizedProductsPath" array. Both methods that I have tried seem to be failing. Can anyone point out what I am doing wrong?
// let categorizedProductsPath: number[][] = [];
let categorizedProductsPath = new Array<number[]>(categorizedProducts.length);
for (let k = 0; k < categorizedProducts.length; k++) {
const categorizedProduct = categorizedProducts[k];
const categoryOfCategorizedProduct = await this.getCategoryToProduct(+categorizedProduct.google_product_category);
let currentParentId = categoryOfCategorizedProduct.parentId;
while (currentParentId !== 0) {
const parentCategory = await this.getCategoryToProduct(currentParentId);
currentParentId = parentCategory.id;
categorizedProductsPath[categorizedProduct.id].push(parentCategory.id); //***
}
}
The error (TypeError: Cannot read properties of undefined (reading 'push')) occurs at this point ***:
categorizedProductsPath[categorizedProduct.id].push(parentCategory.id);
Thank you