Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Sfida: Iterazione Efficiente degli Array con for...of | Padroneggiare Gli Array in JavaScript
Strutture Dati JavaScript

bookSfida: Iterazione Efficiente degli Array con for...of

Compito

Viene fornito un array di oggetti. Ogni oggetto rappresenta le informazioni di un amico. L'obiettivo è creare un ciclo for...of per iterare sull'array e aggiungere una proprietà a ciascun oggetto che deve essere: online: false.

  1. Utilizzare un ciclo for...of per iterare sull'array friends.
  2. All'interno del ciclo for...of, utilizzare la notazione a punto per aggiungere la proprietà.
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

Output previsto:

Friend name is Gail Russel, offline
Friend name is Mrs. Laurie Wunsch, offline
  1. Per creare un ciclo for...of, utilizzare la seguente sintassi: for (const element of array) { ... }.
  2. Utilizzare la notazione a punto (.) per aggiungere una proprietà (online) e assegnarle il valore 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

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 4. Capitolo 8

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

Suggested prompts:

Can you explain how the `for...of` loop works in this example?

What does the `online: false` property represent for each friend?

Can you show how to add a different property to each object in the array?

Awesome!

Completion rate improved to 2.27

bookSfida: Iterazione Efficiente degli Array con for...of

Scorri per mostrare il menu

Compito

Viene fornito un array di oggetti. Ogni oggetto rappresenta le informazioni di un amico. L'obiettivo è creare un ciclo for...of per iterare sull'array e aggiungere una proprietà a ciascun oggetto che deve essere: online: false.

  1. Utilizzare un ciclo for...of per iterare sull'array friends.
  2. All'interno del ciclo for...of, utilizzare la notazione a punto per aggiungere la proprietà.
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

Output previsto:

Friend name is Gail Russel, offline
Friend name is Mrs. Laurie Wunsch, offline
  1. Per creare un ciclo for...of, utilizzare la seguente sintassi: for (const element of array) { ... }.
  2. Utilizzare la notazione a punto (.) per aggiungere una proprietà (online) e assegnarle il valore 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

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 4. Capitolo 8
some-alt