Manuals / JavaScript / Chapter 4
A · Fundamentals · beginner · Week 2 · Chapter 4 of 14
Arrays, objects & destructuring
Arrays hold ordered lists. Objects hold keyed records. map, filter, find, reduce, and some replace index loops for most tasks. Destructuring and spread make copying and unpacking elegant. JSON.parse/stringify connects JS to APIs.
Path progress23%
Step 1 of 5
Array essentials
push/pop/shift/unshift mutate. map/filter/reduce return new arrays — prefer these. find returns first match; some/every return booleans.
Example
const users = [
{ name: "Ava", active: true },
{ name: "Ben", active: false },
{ name: "Cal", active: true },
]
const activeNames = users
.filter(u => u.active)
.map(u => u.name)
const firstActive = users.find(u => u.active)Do this now
Given users = [{name:"Ava",active:true},{name:"Ben",active:false}], filter active, map names, find first active.
Was this step clear?
Chapter learning outcomes
- Array methods
- Object literals & shorthand
- Destructuring & spread
- JSON
- Optional chaining
Clear these before you leave
Side quest
Data transformer
Given a JSON array of orders, return {totalRevenue, orderCount, topCustomer} using map/filter/reduce only.