var data= [{
"item_name": "Jumbo Combo",
"item_key": "9lazhy15tp2fgo72",
"item_price": 25,
"quantity": 1,
"ingredients": [{
"group_key": "fg1udvnz81qwpxtp",
"key": "kcck54k7h3fzp5f0",
"ingredient_name": "Large",
"price": 3
}]
}, {
"item_name": "Swiss & Mushroom Combo",
"item_key": "e1vdfos6s50d5kej",
"item_price": 22,
"quantity": 1,
"dependencies": [{
"group_key": "fg1udvnz81qwpxtp",
"key": "kcck54k7h3fzp5f0",
"name": "Large",
"price": 3
}]
}]
i am interested in calculating the total cost of each item, including both the item_price
and the prices of any additional ingredients. I would like to achieve this using lodash's method sumBy
.
I initially attempted to calculate just the sum of item_price
:
_.sumBy(data, 'item_price')
This successfully calculates the total price of all items in the array based on their item_price
. However, I need to find a way to include the sum of both the ingredients
and the item_price
.