I need to find a better way to implement an extraction of an array from a bigger array and filter that sub-array into a new one, I want to avoid using for loop into another for loop here’s my code:
async function getOrdersList() {
try {
let url = `MY_URL`;
let data = await fetch(url);
let res = await data.json();
if(!res) throw new Error({'error':'no response'});
let orders = res.orders;
let lineItems = [];
let lineItem = {};
for (const [i, value] of orders.entries()) {
let inlineItems = value.line_items;
for (const [j, value2] of inlineItems.entries()) {
lineItem['id'] = value2.shopify_product_id;
lineItem['qty'] = value2.quantity;
lineItems.push(lineItem)
}
}
return lineItems;
}
catch(error) {
console.error(error);
}
}