What is the Array filter() method?
Answer
The filter() method creates a new array containing only the elements for which the callback returns a truthy value. The original array is not modified and the result may be shorter than the original. Syntax: const adults = users.filter(user => user.age >= 18). The callback receives element, index, and array. Chain with map: users.filter(u => u.active).map(u => u.name). Remove falsy values: arr.filter(Boolean) — passes Boolean as a function, removing 0, "", null, undefined, NaN. To remove a specific item by value: arr.filter(item => item !== toRemove). Unlike Array.find() which returns the first matching element (or undefined), filter returns all matches as an array. For checking if any/all elements match a condition, use some() and every() instead.