Course contentsShow
← JavaScript
Lesson 449 of 2,72312. Higher-Order FunctionsFree lesson

Map and Filter with Arrow Functions

Using concise arrow function syntax for cleaner, more readable transformations.

Map and Filter with Arrow Functions

You'll learn how arrow functions make map and filter operations dramatically more concise and readable.

Why Arrow Functions Shine Here

Remember how callbacks in map and filter often contain simple transformations or tests? Arrow functions were practically made for this. Instead of writing verbose function expressions, you can express the same logic in a fraction of the code.

Compare this verbose style:

const numbers = [1, 2, 3, 4, 5];

// Old way
const doubled = numbers.map(function(num) {
  return num * 2;
});

const evens = numbers.filter(function(num) {
  return num % 2 === 0;
});

With the arrow function approach:

// Clean and concise
const doubled = numbers.map(num => num * 2);

const evens = numbers.filter(num => num % 2 === 0);

The Readability Win

Arrow functions eliminate the noise (function keyword, return keyword, curly braces for simple expressions) and let you focus on the transformation logic itself. When you read num => num * 2, you instantly see "take a number, double it."

Chaining becomes elegant:

const prices = [19.99, 5.50, 100, 3.25];

const affordableDoubled = prices
  .filter(price => price < 20)
  .map(price => price * 2);
// [39.98, 11, 6.5]

Think of arrow functions as removing the scaffolding from your code—the essential transformation stands out clearly, making your data pipeline easy to follow at a glance.

Key Takeaway: Arrow functions turn map and filter operations into readable, one-line transformations that clearly express what you're doing rather than obscuring it with syntax.