es5 数组方法:
1: 迭代(遍历)方法:
forEach(), map() 方法 filter() 方法 some() every() 五个方法:
array.forEach(currentValue, index, arr)
1: currentValuel: 数组当前项的值
2: index: 数组当前项索引
3: arr: 数组本身
2: forEach 用法:
forEach 循环遍历数组
let array = [1, 2 ,3] // 定义一个数组
let sum = 0;
array.forEach((value, index, array)=> {
console.log("每一个数组元素" + value)
console.log("每一个数组元素的索引" + index)
console.log("数组本身" + array)
sum += value;
})
console.log(sum) // 可以拿到数组的和