Program to find sum of elements in a given array | javascript Program to find sum of elements in a given array ; Driver code ; calling accumulate function , passing first , last element and initial sum , which is 0 in this case
function accumulate ( arr ) { let sum = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) { sum = sum + arr [ i ] ; } return sum ; } let arr = [ 12 , 3 , 4 , 15 ] ; let n = arr . length ; document . write ( " " + accumulate ( arr ) ) ;