📌  相关文章
📜  如何将所有数组元素与 for - Javascript 代码示例相加

📅  最后修改于: 2022-03-11 15:03:27.583000             🧑  作者: Mango

代码示例2
// define a list
const list = [1,2,3,4,5];

// create a function return result of sum of elements
const result = () => {
  let sum = 0;
  for (let i = 0; i < list.length; i++) {
    sum += list[i];
  }
  return sum
}
console.log(result());