Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ チャレンジ:for...ofによる効率的な配列の反復処理 | JavaScript配列の習得
JavaScriptデータ構造

bookチャレンジ:for...ofによる効率的な配列の反復処理

メニューを表示するにはスワイプしてください

課題

配列として友人情報のオブジェクトが与えられています。各オブジェクトに新しいプロパティ for...of を追加するために、online: false ループを作成してください。

  1. for...of ループを使って friends 配列を反復処理します。
  2. for...of ループ内でドット記法を用いてプロパティを追加します。
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

期待される出力:

Friend name is Gail Russel, offline
Friend name is Mrs. Laurie Wunsch, offline
  1. for...ofループを作成するには、次の構文を使用: for (const element of array) { ... }
  2. ドット記法(.)を使ってプロパティ(online)を追加し、その値に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

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 4.  8
some-alt