數組的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