javascript
Get total sum of specif attribute inside of array of objects
let products = [{
"id": 1,
"product_name": "Forester",
"price": 10
}, {
"id": 2,
"product_name": "Rainier",
"price": 10
}, {
"id": 3,
"product_name": "Yukon Denali",
"price": 10
}, {
"id": 4,
"product_name": "Regal",
"price": 10
}, {
"id": 5,
"product_name": "Alcyone SVX",
"price": 5
}];
let totalPrice = products.reduce((accumulator, current) => {
return accumulator + current.price;
}, 0);
//totalPrice 45
Get total sum of specif attribute inside of array of objects
Was this helpful?
Similar Posts
- Finding the max/min value of an attribute in an array of objects
- Get Top MAX and MIN itens inside array Javascript
- Get the sum of array values using Javascript - Solved
- Count the total number of characters in a textarea while typing in javascript
- Collect books from array of objects and return collection of books as an array
- Bind external value inside .map javascript
- Sort array of objects by key value in Javascript