Given an array [1, 2, 3, 4], how can I find the sum of its elements? (In this case, the sum would be 10.)
[1, 2, 3, 4]
10
I thought $.each might be useful,
You can also use reduceRight.
[1,2,3,4,5,6].reduceRight(function(a,b){return a+b;})
which results output as 21.
Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight