js数组遍历的几种方法

js yekong

for of

let arr = ['ceshi', 'wanjun', 'wanjunshijie']
for (let val of arr) {
    console.log(val)
}

map

let arr = ['wanjunshijie', 'wanjunshijie1', 'wanjunshijie2']
arr.map((val, index) => {
    console.log(index, val)
})

some

let arr = ['wanjunshijie', 'wanjunshijie1', 'wanjunshijie2']
arr.some((val, index) => {
    console.log(index, val)
})

forEach

let arr = ['wanjunshijie', 'wanjunshijie1', 'wanjunshijie2']
arr.forEach((val, index) => {
    console.log(index, val)
})

filter

let arr = ['wanjunshijie', 'wanjunshijie1', 'wanjunshijie2']
arr.filter((val, index) => {
    console.log(index, val)
})

喜欢