📜  forEach 方法 Javascript 代码示例

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

代码示例6
var counter = new Counter();
var numbers = [1, 2, 3];
var sum = 0;
numbers.forEach(function (e) {
    sum += e;
    this.increase();
}, counter);

console.log(sum); // 6
console.log(counter.current()); // 3
Code language: JavaScript (javascript)