1. forEach()方法需要一个函数作为参数
var arr = ['金','木','水','火'];
arr.forEach(function(){
console.log('hello');
})
/*
‘hello’
‘hello’
‘hello’
‘hello’
*/
//(注:这种由我们创建不由我们调用的函数,叫做回调函数)
数组中有几个元素,函数调用几次
2. 当给这个函数带上参数以后
var arr = ['马里奥','塞尔达','路易吉','林克'];
arr.forEach(function(value,index,arr){
console.log('value');
console.log('index');
console.log('arr');
})
第一个参数,就是当前正在遍历的元素
第二个参数,就是当前正在遍历的元素的索引
第三个参数,就是正坐在遍历的数组