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,
i saw all answers going for 'reduce' solution
var array = [1,2,3,4] var total = 0 for (var i = 0; i < array.length; i++) { total += array[i] } console.log(total)