Map Filter Chain in JavaScript

Level 4237 keystrokes

Chaining filter and map methods allows for clean data transformation pipelines.

JavaScript code

// Array of products with name and price
1const products = [
2 { name: "Book", price: 15 },
3 { name: "Pen", price: 3 },
4 { name: "Laptop", price: 999 },
5 { name: "Mouse", price: 25 }
6];
// Chain filter and map methods
7const affordable = products
// Filter products under $50
8 .filter(p => p.price < 50)
// Map to just product names
9 .map(p => p.name);
// Output: ['Book', 'Pen', 'Mouse']
10console.log(affordable);

Output

[ 'Book', 'Pen', 'Mouse' ]
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this JavaScript code and how often they appear.

  • :× 8
  • "× 8
  • ,× 7
  • .× 5
  • {× 4
  • }× 4
  • =× 4
  • ;× 3
  • (× 3
  • )× 3

More JavaScript examples at level 4

← JavaScript typing practice