filter():建立指定函式,由原陣列過濾指定函數產生新陣列
const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present']; const result = words.filter(word => word.length > 6 ); console.log(result); //Array ["exuberant", "destruction", "present"]
Filter去掉重複的元素
1 | let arr = ['B', 'A', 'E', 'C', 'A', 'F', 'G', 'E']; |