var arr = [1, 2, 3, 4, 5, 6,7,8,9,10];

var calc = {
sum: 0
};
function getSum(item, index, array) {
this.sum += item;
console.log(this.sum);
}
arr.forEach(getSum,calc);
console.log('use forEach and change this:sum=' + calc.sum); 

相关文章:

  • 2021-11-18
  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-11
  • 2021-07-10
  • 2022-12-23
  • 2021-07-30
  • 2022-12-23
  • 2021-06-03
相关资源
相似解决方案