I am facing an issue with my code as it lacks flexibility when a new array is added to the nested array, in which case the new array is not considered. My main concern is how to access the elements of each nested array simultaneously.
Here's an example:
const nestedArr = [
[
"ITEM A",
"ITEM B",
"ITEM C"
],
[
"$50.00",
"$30.00",
"$20.00"
],
[
"5",
"2",
"7"
]
]
const ordersObj = []
for (let i=0; i< nestedArr[0].length; i++){
var name = orderArr[0][i];
var price = Number(orderArr[1][i].replace("$",""));
var qty = orderArr[2][i];
var amount = price * qty;
ordersObj.push({name,price,qty,amount})
}
I want to avoid manually specifying positions (0, 1, 2) to access different nested arrays and instead run a loop or modify the code to achieve this dynamically.
Best Regards