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对象

原文地址:https://www.cnblogs.com/huanqiuxuexiji/p/9157550.html