Knowledgize

.filter(fn)

Creates a new array with all elements that pass the test implemented by the provided function.


Examples:

let numbers = [1, 2, 3, 4, 5]; let evenNumbers = numbers.filter(num => num % 2 === 0); console.log(evenNumbers); // [2, 4]
let words = ['spray', 'limit', 'elite', 'exuberant']; let longWords = words.filter(word => word.length > 5); console.log(longWords); // ['exuberant']