Answers for "how sum all array element with while loop"

0

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()
Posted by: Guest on June-19-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language