js思考 ES5之 forEach

array.forEach(function(currentValue, index, arr){}, thisValue)

  array要操作的数组或对象
  currentValue 必需。当前元素(相当于for循环i)
  index     可选。当前元素的索引值(相当于for循环index) 
  arr      可选。当前元素所属的数组对象(相当于for循环arr),不填默认为 array
  thisValue 可选。传递给函数的值一般默认用 "this" 值

demo:

  var array=[1,2,3,4,5];
  array.forEach(function(i,index){console.log(i)})
  // 1 2 3 4 5


tip:

  forEach不能写成foreach
 



 

posted @ 2017-11-25 13:23  haveProgress  阅读(160)  评论(0编辑  收藏  举报