一、arr.filter()
1、创建新数组
2、不改变原数组
3、输出的是判断为true的数组元素形成的新数组
4、回调函数参数,item(数组元素)、index(序列)、arr(数组本身)
5、使用return操作输出,会循环数组每一项,并在回调函数中操作
示例:
- var arr = [1,2,3,4,5] ;
- var newArr = arr.filter(function(item,index){
- return item>2&&item<5 ; //根据判断为true来遍历循环添加进新数组
- })
- console.log(newArr); //打印新数组
- console.log(arr); //打印原数组,map()没有改变原数组