Real programs work with collections — lists of users, rows of data, settings. Arrays hold ordered lists; objects hold labelled properties. Learning to transform them functionally with map, filter and reduce is the skill that separates beginner from fluent JavaScript.
Arrays
const tools = ["Excel", "SQL", "Python"];tools.length; // 3tools[0]; // "Excel" (zero-indexed)tools.push("R"); // add to end → ["Excel","SQL","Python","R"]tools.includes("SQL"); // truetools.indexOf("Python"); // 2
map, filter & reduce
These three methods transform arrays without manual loops. Each takes a function and returns a new value — the originals are untouched:
| Method | Returns | Use for |
|---|---|---|
map | A new array, same length | Transform every item |
filter | A new, shorter array | Keep items that pass a test |
reduce | A single value | Boil a list down to one result (sum, object…) |
const prices = [100, 250, 90, 400];// map — apply GST to eachconst withTax = prices.map(p => p * 1.18);// filter — only the big-ticket itemsconst premium = prices.filter(p => p > 150); // [250, 400]// reduce — total them upconst total = prices.reduce((sum, p) => sum + p, 0); // 840// They chain beautifullyconst bigSpend = prices.filter(p => p > 100).map(p => p * 1.18).reduce((a, b) => a + b, 0);
Objects
An object groups related data under named keys. Access properties with dot or bracket notation:
const student = {name: "Aanya",programme: "Data Analytics",placed: true,skills: ["Excel", "SQL"],greet() { return `Hi, I'm ${this.name}`; } // a method};student.name; // "Aanya"student["programme"]; // bracket notation (needed for dynamic keys)student.greet(); // "Hi, I'm Aanya"student.batch = 2026; // add a new property
An array of objects is the shape of almost all real data (think database rows). map and filter shine here:
const students = [{ name: "Aanya", placed: true, package: 6.5 },{ name: "Rohan", placed: false, package: 0 },{ name: "Priya", placed: true, package: 8.0 },];const placed = students.filter(s => s.placed);const names = placed.map(s => s.name); // ["Aanya", "Priya"]const avg = placed.reduce((a, s) => a + s.package, 0) / placed.length; // 7.25
Destructuring & spread
Destructuring pulls values out of arrays/objects into variables; spread (...) copies or merges them:
const { name, programme } = student; // pull two props into variablesconst [first, second] = tools; // pull array items// Spread — copy and extend without mutating the originalconst updated = { ...student, placed: true };const combined = [...tools, "Tableau"];
Practice
Given the students array above, use the big three to answer: how many are placed, what's the list of placed names, and what's the average package of placed students? Then use spread to add a new student without mutating the array.
Key takeaways
- 01Arrays are ordered, zero-indexed lists; objects are labelled key/value collections.
- 02map transforms every item, filter keeps items that pass a test, reduce collapses to one value.
- 03These methods return new values and can be chained — the source is never mutated.
- 04An array of objects is the shape of real-world data; map/filter/reduce process it cleanly.
- 05Destructuring extracts values; spread (...) copies and merges immutably.
