
📎 This article includes 2 downloadable practice files ↓
In this article
Arrays of objects are JavaScript’s tables. Three methods do most of the work:
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.
Practice
Run the script and add the average order amount.
📎 Practice files for this article
⬇ Download all 2 files (ZIP · 586 B)
- 📄js-05-arrays.jsLesson code file.⬇ JS · 578 B
- 📄js-05-arrays-output.txtOutput from our test run.⬇ TXT · 83 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