I want to get the orders after completing all the pushes to the PrevOrders array. I tried different techniques. when I console the result the array is printed but I can't get the size of it or even manipulate it. How can I get the result?
this.PrevOrders=[];
orderList.forEach(order=>{
let orderObject= order.payload.toJSON();
if(orderObject&&orderObject['status']=="Order Delivered"){
let orderItems=
this.afdb.object(`/OrderItems/${order.key}`);
orderItems.snapshotChanges().subscribe(items=>{
let itemsO=items.payload.toJSON();
let OrderProducts=[];
if(itemsO){
for (const key in itemsO) {
if (itemsO.hasOwnProperty(key))
{
this.afdb.database.ref(`/Items/${key}`)
.child('type').once('value')
.then(item=>{
if(OrderProducts.indexOf(item.toJSON())==-1)
OrderProducts.push(item.toJSON());
});
}
}
this.length=this.PrevOrders.push(OrderProducts);
}
});
}
});
Promise.resolve(orderList).then(()=>{
console.log(this.length);
console.log(this.PrevOrders);
});