J
J
jedifa2021-06-06 14:17:20
JavaScript
jedifa, 2021-06-06 14:17:20

How to add numbers in an array of objects?

I have such an array, const arr = [{price: 20}, {price: 30}];how do I add price 20 to price 30?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2021-06-06
@jedifa

const total = arr.reduce((acc, item) => acc + item.price, 0);

L
Lynn "Coffee Man", 2021-06-06
@Lynn

arr[0].price + arr[1].price

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question