标签:
<script> var a = [1,2,3,4,5,6]; var b = a.some(function(ele,index,arr){ console.log(ele);//输出1,2,3遍历到3停止遍历 return ele > 2; }); alert(b); var c = a.every(function(ele,index,arr){ console.log(ele);//输出1,2,3,4,5遍历到5返回false,停止遍历 return ele < 5; }); alert(c); var d = a.filter(function(ele,index,arr){ console.log(ele);//遍历整个数组,将值大于3的项添加到d数组中 return ele > 3; }); alert(d); var e = a.map(function(ele,index,arr){ console.log(ele);//遍历整个数组,对数组的每个元素执行一次操作,将新的元素添加到e数组中 return ele+3; }); alert(e); a.forEach(function(ele,index,arr){ arr[index] = ele+6;//遍历数组,对数组中的每项执行一次操作,无返回值 }); alert(a); </script>
标签:
原文地址:http://www.cnblogs.com/pmx-pmx/p/5821473.html