Skip to content

Instantly share code, notes, and snippets.

@Yigaue
Created May 18, 2020 01:20
Show Gist options
  • Save Yigaue/19bbdbd7d80b930154234750c2d20857 to your computer and use it in GitHub Desktop.
Save Yigaue/19bbdbd7d80b930154234750c2d20857 to your computer and use it in GitHub Desktop.
let data = [
{id: 1, title: 'Nite watch', price: 33, discount:0},
{id: 2, title: 'what I want', price: 12, discount:0.4},
{id: 3, title: 'Mercy at last', price: 405, discount:0.25},
{id: 4, title: 'Nothting between', price: 550, discount:0}
];
priceSum = data.reduce((acc, currentValue) => acc + currentValue.price, 0);
console.log(priceSum);
// console result
1000
priceSum = data.reduce((acc, currentValue) => acc + currentValue.price);
console.log(priceSum);
// console result
"[object Object]12405550"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment