Skip to content

Instantly share code, notes, and snippets.

@just1and0
Created February 27, 2020 13:04
Show Gist options
  • Save just1and0/b477f2a9cb741ad15f045031fdf690bd to your computer and use it in GitHub Desktop.
Save just1and0/b477f2a9cb741ad15f045031fdf690bd to your computer and use it in GitHub Desktop.
// data
var data = [{"name":"ramu","id":"719","gmail":"[email protected]","ph":988989898,"points":36},
{"name":"ravi","id":"445","gmail":"[email protected]","ph":4554545454,"points":122},
{"name":"karthik","id":"866","gmail":"[email protected]","ph":2332233232,"points":25}]
// sum all data in points
var result = data.reduce(function(tot, arr) {
// return the sum with previous value
return tot + arr.points;
// set initial value as 0
},0);
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment