Skip to main content
Albero Academy

Arrays & Objects

Store collections and structured data, then transform them with map, filter and reduce — the heart of modern JavaScript.

Chapter 3JavaScript16 min readBeginner friendly
  • #JavaScript
  • #Arrays
  • #Objects

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

array basics
const tools = ["Excel", "SQL", "Python"];
tools.length; // 3
tools[0]; // "Excel" (zero-indexed)
tools.push("R"); // add to end → ["Excel","SQL","Python","R"]
tools.includes("SQL"); // true
tools.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:

MethodReturnsUse for
mapA new array, same lengthTransform every item
filterA new, shorter arrayKeep items that pass a test
reduceA single valueBoil a list down to one result (sum, object…)
the big three
const prices = [100, 250, 90, 400];
// map — apply GST to each
const withTax = prices.map(p => p * 1.18);
// filter — only the big-ticket items
const premium = prices.filter(p => p > 150); // [250, 400]
// reduce — total them up
const total = prices.reduce((sum, p) => sum + p, 0); // 840
// They chain beautifully
const 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:

objects
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:

array of objects
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:

destructuring & spread
const { name, programme } = student; // pull two props into variables
const [first, second] = tools; // pull array items
// Spread — copy and extend without mutating the original
const 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

  1. 01Arrays are ordered, zero-indexed lists; objects are labelled key/value collections.
  2. 02map transforms every item, filter keeps items that pass a test, reduce collapses to one value.
  3. 03These methods return new values and can be chained — the source is never mutated.
  4. 04An array of objects is the shape of real-world data; map/filter/reduce process it cleanly.
  5. 05Destructuring extracts values; spread (...) copies and merges immutably.