1.遍历数组forEach()
只遍历不返回值,加强版的for循环,适合遍历数组对象
const arr = ['red', 'green', 'blue']
// arr.forEach(function (item, index) 参数部分item必须写,index可以不写
arr.forEach(function (item, index) {
console.log(item) //数组里的每个元素
console.log(index) //每个元素的索引号
})
2.filter()筛选数组
有返回值,返回的是新数组