JavaScript · Beginner level

Beginner level · Module 3: Arrays, Objects and Array Methods · Lesson 1 of 3

Arrays and Objects

Store lists in arrays and records in objects, read and change them, and unpack them with destructuring.

In this lesson you will

  • Create, read and modify arrays and objects
  • Use destructuring to unpack values

Key concepts

array index and lengthobject propertiesdot vs bracket notationdestructuring

The lesson

An array holds an ordered list: const prices = [3500, 2800, 1200];. Indexes start at 0, length gives the count, push adds to the end and slice copies part of an array without changing it.

An object groups related values under names: const product = { name: "Rice", price: 3500 };. Read with product.name, or product[key] when the property name is in a variable. Real data is usually an array of objects, like rows in a table.

Destructuring unpacks values: const { name, price } = product; const [first, second] = prices;. It is common in modern code and makes function parameters clearer.

Step by step

  1. Create an array of prices and add one with push.
  2. Create a product object and read its properties.
  3. Create an array of three product objects.
  4. Destructure the first product's name and price.

Practice activity

Model a small shop's stock as an array of objects and print each item's name, price and quantity.

Expected result: Every item prints correctly, using property access or destructuring.

Check your understanding

  1. How do you read a property whose name is stored in a variable key?

    Show answer

    With bracket notation: obj[key].

  2. What does const { name } = product; do?

    Show answer

    Creates a variable name holding product.name.

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.