LESSON 07 OF 10
Objects and Array Methods
Describe related data and transform collections.
Before this lesson: complete the preceding lessons or review their examples. No installation or account is needed.
The idea
An object groups named properties. Dot notation reads a known property; bracket notation is useful for a property name held in a variable. Arrays can contain objects, allowing you to describe a collection of related records.
At a glance
| Syntax | Purpose |
|---|---|
object.property | Read a named value |
.filter(callback) | Create an array of items passing a test |
.map(callback) | Create an array of transformed values |
Try it yourself
Change one completed value to see filter select a different collection.
Ready. Run the example to open its preview.
Console output
Not run yet.
Page preview
Expected result
Variables
What to watch for
An arrow function such as lesson => lesson.title returns its expression. With a block body, write return explicitly. map and filter create new arrays; if their elements are objects, those objects can still be shared with the original array.
Your turn
Create a learner object with name and points properties, then print the name and increase points by 5.
Show one solution
const learner = { name: "Nicole", points: 10 };
learner.points += 5;
console.log(learner.name, learner.points);Check your understanding
Does filter change the original array?
filter creates a new array containing selected elements. It does not remove elements from the original array.