Skip to content

Instantly share code, notes, and snippets.

@walidum
Last active May 3, 2021 09:36
Show Gist options
  • Save walidum/8bb01719d253cbf19ef93c1fa1fd12bf to your computer and use it in GitHub Desktop.
Save walidum/8bb01719d253cbf19ef93c1fa1fd12bf to your computer and use it in GitHub Desktop.
How to call reduce on an array of objects to sum their properties?
const arr = [{x:1}, {x:2}, {x:4}];
const res = arr.reduce((acc, item) => acc + item.x, 0);
console.log(res); //=> 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment