javascript的数组之filter()

filter()方法创建一个新数组,其包含通过回调函数测试的所有元素。

const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];

const result = words.filter(word => word.length > 6); // ["exuberant", "destruction", "present"]

 

参数:

第一个:回调函数callback(ele, index, array),返回true保留该元素,否则flase丢掉

第二个:回调函数的this对象

posted @ 2018-06-08 20:55  环球学习机  阅读(447)  评论(0编辑  收藏  举报