JavaScript for Excel Users: Arrays, map, filter and reduce Explained

JavaScript for Excel Users: Arrays, map, filter and reduce Explained

📎 This article includes 2 downloadable practice files ↓

⏱ 2 min readUpdated 28 September 2026

JavaScript runs in every browser, powers Office Scripts and Google Apps Script, and is the language of the web. The fastest way in for an Excel user is through arrays — because a column in Excel is basically an array.

In this article
  1. Your data as an array of objects
  2. filter = AutoFilter / FILTER()
  3. map = a formula column
  4. reduce = SUM / SUMIFS
  5. sort = Sort largest to smallest
  6. Group by = pivot table
  7. Where to go next
  8. Continue learning

Press F12 in your browser, open the Console tab, and paste the examples.

Advertisement

Your data as an array of objects

const sales = [
  { rep: "Asha",  region: "North", amount: 12500 },
  { rep: "Rohit", region: "South", amount:  8400 },
  { rep: "Meera", region: "North", amount: 15200 },
  { rep: "Karan", region: "East",  amount:  6100 },
];

Each { } is a row; rep, region, amount are the column headers.

filter = AutoFilter / FILTER()

const north = sales.filter(s => s.region === "North");
// Excel: =FILTER(A2:C5, B2:B5="North")

map = a formula column

const withTax = sales.map(s => ({ ...s, tax: s.amount * 0.18 }));
// Excel: new column D with =C2*0.18

reduce = SUM / SUMIFS

const total = sales.reduce((sum, s) => sum + s.amount, 0);             // =SUM(C2:C5)
const northTotal = north.reduce((sum, s) => sum + s.amount, 0);        // =SUMIFS(C:C, B:B, "North")

sort = Sort largest to smallest

const ranked = [...sales].sort((a, b) => b.amount - a.amount);
// Excel: =SORTBY(A2:C5, C2:C5, -1)
💡 [...sales] makes a copy first — sort() changes the original array, which surprises almost everyone the first time.

Group by = pivot table

const byRegion = {};
for (const s of sales) {
  byRegion[s.region] = (byRegion[s.region] || 0) + s.amount;
}
console.table(byRegion);   // { North: 27700, South: 8400, East: 6100 }

console.table prints a neat table — your first “pivot”.

Where to go next

📎 Practice files for this article

⬇ Download all 2 files (ZIP · 586 B)

  • 📄
    Arrays scriptPractice file from the matching course lesson.
    ⬇ JS · 578 B
  • 📄
    Expected outputPractice file from the matching course lesson.
    ⬇ 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