
📎 This article includes 2 downloadable practice files ↓
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
Press F12 in your browser, open the Console tab, and paste the examples.
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
- Automate Excel on the web with the same syntax: Office Scripts.
- Prefer SQL for data questions? Try the SQL Playground.
📎 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.
Atul (AJ) builds office-automation and local-first AI tools as Atulya AI, and works with Excel, SAP and Oracle EPM every day. He writes about the shortcuts, macros and automations that actually save time — plus the occasional wacky fact. Videos on YouTube: Lazy Automator AI (@LazyAutomatorAI).
More posts by Atul →Stuck on a step? Ask a question and the AI answers using this article.