js的数组迭代器函数map和filter,可以遍历数组时产生新的数组,和python的map函数很类似
1)filter是满足条件的留下,是对原数组的过滤;
2)map则是对原数组的加工,映射成一一映射的新数组
var xx = [1, 2, 5, 7];
function pp(x){return x % 2;}
function px(x){return x % 2;}
var m = xx.map(pp);
console.log("m = " + m);
var f = xx.filter(px);
console.log("f = " + f);
.........................................................................
m = 1,0,1,1
f = 1,5,7
相关文章
- python中的enumerate、map、filter和zip函数
- Python 函数式编程 & Python中的高阶函数map reduce filter 和sorted
- JavaScript中的apply和call函数详解(转)
- Python函数式编程中map()、reduce()和filter()函数的用法
- Python 函数式编程 & Python中的高阶函数map reduce filter 和sorted
- 简单介绍Python中的filter和lambda函数的使用
- Python中map,reduce,filter和sorted函数的使用方法
- Python3版本中的filter函数,map函数和reduce函数
- javascript中map,reduce,filter,sort函数的用法
- Python3版本中的filter函数,map函数和reduce函数