forEach与for的区别
const arr2 = [7, 8, 9];
angular.forEach(arr, (arrItem) => {
if (arrItem == 3) {
arr.push(5);
}
console.log('arrItem', arrItem);
});
for (let i = 0; i < arr2.length; i++) {
if (arr2[i] == 7) {
arr2.push(5);
}
console.log('arrItem', arr2[i]);
}
具体体现为:for在循环中,对遍历对象arr的修改能及时生效。而forEach择不会。如有看法相左之处,还请各位多多留言讨论