数组迭代的一些方法

  1. for循环--最普通的方法
  2. arr.forEach(function(value, index, array){})--遍历数组-----map()相似
  3. arr.filter(function(value, index, array){ return value > 20;})--筛选数组--返回的是一个新的数组
  4. arr.some(function(val, index, arr){ return value > 20;})--查找是否没有满足条件的元素,返回布尔值---查找到第一个符合条件的元素,则停止循环-----every()相似

猜你喜欢

转载自www.cnblogs.com/joeynkay/p/12735335.html