数组的filter用法


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

语法:var new_array = arr.filter(callback(element[, index[, array]])[, thisArg])

1 var words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
2 
3 const result = words.filter(word => word.length > 6);
4 
5 console.log(result);
6 // expected output: Array ["exuberant", "destruction", "present"]

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM