
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.