ES6 Array对象方法filter()
ES6 Array对象方法filter()
filter()方法创建一个新的数组,其中包含符合测试条件的的所有元素。
语法
array.filter(callback[, thisObject]);
参数
callback − 需要测试元素的函数.
thisObject − 对象在执行回调时用作此操作.
返回值
返回创建后的数组
例子
function isBigEnough(element, index, array) { return (element >= 10); } var passed = [12, 5, 8, 130, 44].filter(isBigEnough); console.log("Test Value : " + passed );
输出
Test Value :12,130,44