Front-end and full stack · Chapter 4
Arrays and objects: the methods you reach for daily
About this chapter
Front-end code spends most of its time reshaping lists and records. This chapter sorts the everyday array and object methods by one question, whether they change the original or return something new, then covers reduce, spreading and destructuring, missing values, copies and equality, and when a Map or a Set fits better than an object.
Who it is for: Developers who write JavaScript every day and want to know which methods change data in place, which return new data, and why that matters in a front end.
You will be able to
- Know which array methods alter their own array and which hand back a fresh copy.
- Chain map, filter and flatMap to prepare data for a screen.
- Use reduce to build a number, an object or an array from a list.
- Read nested data safely with optional chaining and supply defaults with nullish coalescing.
- Explain why strict equality on two objects compares identity rather than contents, and make copies that share no data.
The key idea: Data bugs in a front end are usually about sharing, not about syntax: two parts of a page hold the same array and one of them changes it. Knowing which operations copy and which change in place is what makes the other methods safe to use.
In this chapter
- Paperlark's catalogue as data
- Mutating or not: the question to ask first
- Transforming, searching and iterating
- reduce: one value from many
- Objects: entries, spread, rest and destructuring
- Missing values: optional chaining and nullish coalescing
- Equality, copies and JSON
- Map and Set
- Putting it together: the basket view
- Mistakes that recur
Locked: needs a plan
You can read chapter 1 free. Chapter 4 is the next one.
What you can do now, free: re-read chapter 1 and try its problems.
What a plan gives you: all chapters of the track you pick and their checks. Professional, one role is ₹329 a month or ₹2,299 a year. It renews until you cancel, and you can cancel any time. Paid plans open at launch.
Why is this locked?
Chapter 1 of every track is free, so you can see how the track reads. The rest of a track and its checks come with a plan, or open as you pass each chapter's check.
The price is for one period, a month or a year. A plan renews until you cancel.