filter() - Select Elements in JavaScript

From the JavaScript Array Methods cheat sheet · Transformation Methods · verified Jul 2026

filter() - Select Elements

Create a new array with elements that pass a test

javascript
// Keep elements that pass the test
const evens = [1, 2, 3, 4].filter(x => x % 2 === 0);
// [2, 4]

const adults = users.filter(u => u.age >= 18);

// Remove falsy values
const truthy = [0, 1, '', 'hello', null].filter(Boolean);
// [1, 'hello']
🟢 Essential - Use for selecting subset of elements
💡 Returns new array with filtered items
⚡ Chainable with other array methods
📌 Original array remains unchanged
⚠️ Returns empty array if nothing matches

Continue with JavaScript Array Methods

Save the full cheat sheet or work through every related task.

More JavaScript tasks

Back to the full JavaScript Array Methods cheat sheet