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.


