0
点赞
收藏
分享

微信扫一扫

JavaScript - forEach

E_topia 2022-03-11 阅读 15

数组常用方法

-forEach()
-专门用来遍历数组的方法

语法

数组.forEach(function (item, index, arr){
// item 表示数组的每一项
// index 表示数组每一项的索引
// arr 表示原始数组
})

返回值

-没有,undefined

    var arr = [ 100, 200, 300, 400, 500, 600 ]
    var arr2 = [ 10, 20, 30, 40 ]

    // a 会根据数组内有多少数据, 执行多少回
    arr.forEach(function a(item, index, arr) {
      console.log('我执行了', item, index, arr)
    //   // 可以直接书写每一次循环你要做的事情
    })
举报

相关推荐

0 条评论