Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

sum array elements in javascript

console.log(
  [1,2,3].reduce(function(acc, val) { return acc + val; })
)

console.log(
  [].reduce(function(acc, val) { return acc + val; }, 0)
)
 Run code snippetHide results
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #sum #array #elements #javascript
ADD COMMENT
Topic
Name
1+3 =