JS基础 - 数组 - 高级API - forEach方法

forEach()方法

对数组进行遍历循环,对数组中的每一项运行指定的函数

格式:

arr.forEach(function(value, index) {})
var arr = [1, 3, 5, 7, 9, 11];

arr.forEach(function(value, index) {
    console.log(index + ":" + value)
})

猜你喜欢

转载自blog.csdn.net/weixin_37580235/article/details/80749734
今日推荐