JavaScript:数组遍历
1、forEach
let arr = [1,2,3,4,5]arr.forEach(function(item,index,arr){arr[index] = item + 1
})
console.log(arr) // [2,3,4,5,6]
2、map
let arr = [1,2,3,4,5]let newArr = arr.map(function(item,index,arr){return item+1
})
console.log(newArr) // [2,3,4,5,6]