标签:
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
JavaScript中map函数和filter的简单举例(转)
标签:
原文地址:http://www.cnblogs.com/tim100/p/5944051.html