Chrome Extension

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

Do you know, you can create and search your own code snippets on Devsheet. Store your code on cloud using devsheet and search using its chrome extension. Is it look cool?

Get total sum of specif attribute inside of array of objects 

Search Index Data (The code snippet can also be found with below search text)

Get total sum of specif attribute inside of array of objects
Was this helpful?
0 Comments
Never leave your website again in search of code snippets by installing our chrome extension.