Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Efficient Array Iteration with for...of | Mastering JavaScript Arrays
JavaScript Data Structures

bookChallenge: Efficient Array Iteration with for...of

Task

You are given an array of objects. Each object represents a friend's information. The task is to create a for...of loop to iterate through the array and add one more property to each object that should be: online: false.

  1. Use a for...of loop to iterate through the friends array.
  2. Inside the for...of loop, use the dot notation to add the property.
123456789101112131415161718192021222324
const friends = [ { name: "Gail Russel", address: "803 Kozey Rapid", phone: "(317) 833-9935 41777", }, { name: "Mrs. Laurie Wunsch", address: "7361 Austin Road", phone: "(728) 884-9049 4760", }, ]; // Use a `for...of` loop for (const friend of ___) { friend.___ = ___; } // Logging specific properties after modifications for (const friend of friends) { console.log( `Friend name is ${friend.name}, ${friend.online ? "online" : "offline"}` ); }
copy

Expected Output:

Friend name is Gail Russel, offline
Friend name is Mrs. Laurie Wunsch, offline
  1. To create a for...of loop, use the following syntax: for (const element of array) { ... }.
  2. Use the dot notation (.) to add a property (online) and assign it the value false.
123456789101112131415161718192021222324
const friends = [ { name: "Gail Russel", address: "803 Kozey Rapid", phone: "(317) 833-9935 41777", }, { name: "Mrs. Laurie Wunsch", address: "7361 Austin Road", phone: "(728) 884-9049 4760", }, ]; // Use a `for...of` loop for (const friend of friends) { friend.online = false; } // Logging specific properties after modifications for (const friend of friends) { console.log( `Friend name is ${friend.name}, ${friend.online ? "online" : "offline"}` ); }
copy

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 8

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Awesome!

Completion rate improved to 2.27

bookChallenge: Efficient Array Iteration with for...of

Свайпніть щоб показати меню

Task

You are given an array of objects. Each object represents a friend's information. The task is to create a for...of loop to iterate through the array and add one more property to each object that should be: online: false.

  1. Use a for...of loop to iterate through the friends array.
  2. Inside the for...of loop, use the dot notation to add the property.
123456789101112131415161718192021222324
const friends = [ { name: "Gail Russel", address: "803 Kozey Rapid", phone: "(317) 833-9935 41777", }, { name: "Mrs. Laurie Wunsch", address: "7361 Austin Road", phone: "(728) 884-9049 4760", }, ]; // Use a `for...of` loop for (const friend of ___) { friend.___ = ___; } // Logging specific properties after modifications for (const friend of friends) { console.log( `Friend name is ${friend.name}, ${friend.online ? "online" : "offline"}` ); }
copy

Expected Output:

Friend name is Gail Russel, offline
Friend name is Mrs. Laurie Wunsch, offline
  1. To create a for...of loop, use the following syntax: for (const element of array) { ... }.
  2. Use the dot notation (.) to add a property (online) and assign it the value false.
123456789101112131415161718192021222324
const friends = [ { name: "Gail Russel", address: "803 Kozey Rapid", phone: "(317) 833-9935 41777", }, { name: "Mrs. Laurie Wunsch", address: "7361 Austin Road", phone: "(728) 884-9049 4760", }, ]; // Use a `for...of` loop for (const friend of friends) { friend.online = false; } // Logging specific properties after modifications for (const friend of friends) { console.log( `Friend name is ${friend.name}, ${friend.online ? "online" : "offline"}` ); }
copy

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 8
some-alt