Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how sum all array element with while loop

// define a list
const list = [1,2,3,4,5];

// arrow function to sum array element
const result2 = () => {
  var i = list.length;
  var sum = 0;
  while (i--) {
    sum += list[i]
  }
  console.log(sum)
}
result2()
 
PREVIOUS NEXT
Tagged: #sum #array #element #loop
ADD COMMENT
Topic
Name
1+3 =