Lesson 3 of 3

Arrays and Objects

Learn to work with JavaScript's most important data structures: arrays for lists and objects for structured data.

28 minutes

Arrays and Objects

Arrays and objects are fundamental data structures in JavaScript.

Arrays

Arrays store ordered collections of items:

  • Access items by index (starting at 0)
  • Use methods like push(), pop(), map(), filter()
  • Perfect for lists of similar items

Objects

Objects store key-value pairs:

  • Access properties with dot notation or brackets
  • Can contain any data type as values
  • Perfect for structured data

Array Methods

  • map(): Transform each item
  • filter(): Keep items that match a condition
  • reduce(): Combine all items into one value
  • find(): Get first item matching a condition

Destructuring

Modern JavaScript lets you unpack values easily from arrays and objects.

Code Example

// Arrays
const fruits = ["apple", "banana", "orange"];
fruits.push("grape");

const doubled = [1, 2, 3].map(n => n * 2);
console.log(doubled); // [2, 4, 6]

// Objects
const user = {
  name: "Elena",
  age: 28,
  skills: ["JavaScript", "React", "Node.js"]
};

console.log(user.name); // Elena
console.log(user.skills[0]); // JavaScript

// Destructuring
const { name, age } = user;
const [first, second] = fruits;