Destructuring Objects by Name

Your port can take a chip row apart and join the two start waves into one array of records. Each results line, though, needs only a few fields from one runner, and the Python script reads them one lookup at a time. In this lesson, you’ll take them by name in a single line.

Take Fields by Name

Where the Python script writes name = runner["name"] and finish = runner["finish"], JavaScript takes both in one declaration. Here it is on Mei Chen’s record:

Language: JavaScript
const runner = {
  bib: 23, name: "Mei Chen", group: "F35",
  checkpoints: ["0:22:40", "", "1:08:55"],
  finish: "1:36:20",
};

const { finish, name } = runner;
console.log(name, finish);

Each variable gets the value of the property with the same name:

Language: Program Output
Mei Chen 1:36:20

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.