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);
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);