3. Modern JavaScript Fundamentals

JavaScript Arrays, Objects & Modern ES6 Methods

Master real-world JavaScript data structures: objects, arrays, destructuring, spread syntax (...), for...of loops, and .map(), .filter(), .find(), and .reduce().

4 min readUpdated 2026-11-29
In This Lesson
  • Model structured records using JavaScript objects and ordered lists with arrays
  • Unpack properties cleanly with destructuring and copy data safely using the spread operator (...)
  • Transform, search, filter, and summarize lists using .map(), .filter(), .find(), and .reduce()

Almost every real web app works with lists of structured items: a feed of social posts, products in a shopping cart, rows in a study planner, or courses in a catalog. In JavaScript, you represent each item as an object { ... } and a collection of items as an array [ ... ].

Objects & Arrays: Storing Structured Data

An object groups related named properties (key: value), while an array holds an ordered zero-indexed list:

javascript
const course = {
  title: "Web Foundations",
  lessons: 16,
  free: true,
};

// Dot notation (most common) vs bracket notation (dynamic keys)
console.log(course.title);     // "Web Foundations"
console.log(course["free"]);   // true

const tracks = ["HTML", "CSS", "JavaScript"];
console.log(tracks[0]);        // "HTML"
console.log(tracks.length);    // 3

Notice also optional chaining (?.): writing user.profile?.city safely returns undefined instead of crashing the whole app if profile happens to be missing on a newly created account!

ES6 Superpowers: Destructuring & Spread (...)

Before exploring array methods, learn two shorthand syntaxes you will see constantly in modern JavaScript, React, and Next.js:

  1. Destructuring unpacks properties into standalone variables in one line:
javascript
const student = { fullName: "Maya Chen", track: "Web Dev", streak: 12 };
const { fullName, streak } = student;

console.log(fullName, streak); // "Maya Chen" 12
  1. Spread (...) copies items or properties into a brand-new array or object without mutating the original:
javascript
const baseTasks = ["Read Lesson 1", "Try Playground"];
const updatedTasks = [...baseTasks, "Pass Quiz"]; // New array! baseTasks stays untouched

const updatedStudent = { ...student, streak: 13 }; // Copies fields, overrides streak

Looping vs Transforming (.filter(), .map(), .find(), .reduce())

To run code once per element without needing index variables (i = 0), reach for for...of:

javascript
for (const track of ["HTML", "CSS", "JS"]) {
  console.log("Learning:", track);
}

When you want to compute a new result from an array without mutating the original array, modern JavaScript provides four declarative array methods:

MethodQuestion It AnswersReturns
.filter(fn)"Which items match this rule?"A new array of matching items (0 to many)
.find(fn)"What is the FIRST item matching this rule?"One item (or undefined if none found)
.map(fn)"How should each item be transformed?"A new array of exact same length with transformed values
.reduce(fn, start)"How do all items combine into one summary value?"A single value (sum total, max number, count object)

Because .filter() and .map() both return clean arrays, you can chain them top-to-bottom like an assembly line:

javascript
const courses = [
  { title: "Python", hours: 20, featured: true },
  { title: "Git", hours: 8, featured: false },
  { title: "Web Dev", hours: 15, featured: true },
];

const featuredTitles = courses
  .filter((course) => course.featured)
  .map((course) => `${course.title} (${course.hours}h)`);

console.log(featuredTitles); // ["Python (20h)", "Web Dev (15h)"]

Try It Live: Filter, Map & Total Revenue

Practice inspecting, filtering, and totaling real product objects below—try adding .find() to locate "Tea" by name:

JavaScriptLive JS — .filter(), .map() & .reduce()
Output

Click “Run Code” to execute this snippet right in your browser.

Using .sort() or .push() When You Wanted an Immutable Copy

Methods like .push() and .sort() modify the original array in place. Whenever you want the original array untouched, copy it first with spread syntax: const sorted = [...scores].sort((a, b) => b - a);.

Quick Checkpoints

Check Your Understanding

What does [1, 2, 3, 4].filter((n) => n > 2) return?

Check Your Understanding

Which method stops as soon as it locates the SINGLE matching item (for example, finding a user by id) instead of scanning for an array of matches?