Declare array of objects

Aug 23 2020 6:21 AM
I need to store array of objects and then convert that into string using JSON.stringify and transfer that string to external link. Below is my typescript code..
 
let orderItems: any[] = [];
let order_data = {};
 
this.storage.get("cart").then((cart) => {
   cart.forEach((element, index) => {
         orderItems.push({ "product_id": element.product.id, "quantity": element.qty });
         });
   });
console.log(orderItems);
order_data = {
"customer_name": "Singh",
"line_items": orderItems,
}
console.log(JSON.stringify(order_data));
 
 In my console I got empty array of objects.....   {"customer_name":"Singh","line_items":[]}
 
Anyone here pls help me out of this... Thank you in advance.... 

Answers (2)