freeCodeCamp/curriculum/challenges/chinese/02-javascript-algorithms-an.../basic-javascript/accessing-nested-arrays.chi...

2.0 KiB
Raw Blame History

id title challengeType guideUrl videoUrl localeTitle
56533eb9ac21ba0edf2244cd Accessing Nested Arrays 1 https://chinese.freecodecamp.org/guide/certificates/access-array-data-with-indexes 访问嵌套数组

Description

正如我们在前面的示例中所看到的,对象可以包含嵌套对象和嵌套数组。与访问嵌套对象类似,可以链接数组括号表示法来访问嵌套数组。以下是如何访问嵌套数组的示例:
var ourPets = [
{
animalType“猫”
名称:[
“Meowzer”
“蓬松”,
“洁猫”
]
}
{
动物类型:“狗”,
名称:[
“点”,
“库巴”
“羊羊”
]
}
]。
ourPets [0] .names [1]; //“蓬松”
ourPets [1] .names [0]; //“Spot”

Instructions

使用对象点和数组括号表示法从变量myPlants检索第二个树。

Tests

tests:
  - text: <code>secondTree</code>应该等于“松树”
    testString: 'assert(secondTree === "pine", "<code>secondTree</code> should equal "pine"");'
  - text: 使用点和括号表示法访问<code>myPlants</code>
    testString: 'assert(/=\s*myPlants\[1\].list\[1\]/.test(code), "Use dot and bracket notation to access <code>myPlants</code>");'

Challenge Seed

// Setup
var myPlants = [
  {
    type: "flowers",
    list: [
      "rose",
      "tulip",
      "dandelion"
    ]
  },
  {
    type: "trees",
    list: [
      "fir",
      "pine",
      "birch"
    ]
  }
];

// Only change code below this line

var secondTree = ""; // Change this line

After Test

console.info('after the test');

Solution

// solution required