I have an order array. I don't see how could I summarize the orders with price and quantity. I wanted to get the prices and quantity from item object and summing it, but how could do that?
{
"orders" : [ null, {
"date" : "2018-07-09 10:07:18",
"item" : [ {
"name" : "Warmer Topfenstrudel",
"price" : 3.9,
"quantity" : 1
} ]
}, {
"date" : "2018-07-09 10:07:30",
"item" : [ {
"name" : "Warmer Topfenstrudel",
"price" : 3.9,
"quantity" : 1
} ]
}, {
"date" : "2018-07-09 15:07:18",
"item" : [ {
"name" : "Piccata Milanese",
"price" : 12.9,
"quantity" : 3
} ]
}, {
"date" : "2018-06-13 10:07:18",
"item" : [ {
"name" : "Wiener Schnitzel vom Schwein",
"price" : 9.9,
"quantity" : 2
} ]
} ]
}
I tried following function:
getTotal: function(arr) {
return arr.reduce((sum, i) => {
return sum + (i.price * i.quantity)
},0)
},
getTotal()asarr? Eachitemis an array