JavaScript Lesson 5: Arrays — map, filter, reduce

JavaScript Lesson 5: Arrays — map, filter, reduce featured illustration

📎 This article includes 2 downloadable practice files ↓

⏱ 1 min readUpdated 12 October 2026

📘 JavaScript Beginner Course · Lesson 5 of 8

In this article
  1. Sorting
  2. Practice
  3. Continue learning

Arrays of objects are JavaScript’s tables. Three methods do most of the work:

Advertisement
const big = orders.filter(o => o.amount > 10000);           // like FILTER
const ids = big.map(o => o.id);                              // transform each row
const total = orders.reduce((s, o) => s + o.amount, 0);      // like SUM
const byRegion = orders.reduce((acc, o) => ({ ...acc, [o.region]: (acc[o.region] || 0) + o.amount }), {});   // like SUMIF

Sorting

[...orders].sort((a, b) => b.amount - a.amount) sorts largest first. The [...orders] copy matters: sort changes the array in place.

⚠️ Sorting numbers without a compare function sorts them as text: [10, 9, 100].sort() gives [10, 100, 9].
💡 Chain methods: orders.filter(…).map(…).slice(0, 5) reads like a recipe: filter, transform, take the top 5.

More: arrays for Excel users.

Advertisement

Practice

Run the script and add the average order amount.

📎 Practice files for this article

⬇ Download all 2 files (ZIP · 586 B)

Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.

✨ Ask AI about this article

Stuck on a step? Ask a question and the AI answers using this article.

Free · AI can be wrong