Skip to content
Parwaz DigitalMarketing · Web · Courses

Web Development Course · Module 3, lesson 3

Working with arrays and objects

Store lists in arrays and structured data in objects, then transform them with array methods like map, filter and find.

What you will learn

  • Create and read from arrays and objects
  • Transform data with map, filter and find
  • Recognise the link between JavaScript objects and JSON

An array is an ordered list, written in square brackets: const items = ["bread", "cake", "biscuits"]. Items are counted from zero, so items[0] is "bread", and items.length gives the count. An object groups related values under named keys, written in curly braces: const product = { name: "Cake", price: 1200, inStock: true }. Read a value with product.name.

Real data is usually an array of objects, such as a list of products each with a name and price. Array methods make this easy to work with. map creates a new array by transforming each item, for example getting just the names. filter keeps only items that pass a test, such as products in stock. find returns the first matching item, or undefined if there is none.

These methods do not change the original array, which makes code easier to follow. Destructuring is a handy shortcut for pulling values out: const { name, price } = product creates two variables at once. Objects and arrays are also the shape of JSON, the text format most web APIs use to send data, so these skills carry straight into the next lessons.

Practice task

Create an array of six bakery products as objects with name, price and inStock. Use filter to list the in-stock items and map to produce an array of their names.

Web Development Course

Learn this properly,with a final project.

These pages summarise each lesson. The full course teaches them hands-on. Message us for the current fee, schedule, and format.

Available for new projects — Replies within one business day