--- id: 56533eb9ac21ba0edf2244cd title: Accessing Nested Arrays challengeType: 1 guideUrl: 'https://chinese.freecodecamp.org/guide/certificates/access-array-data-with-indexes' videoUrl: '' localeTitle: 访问嵌套数组 --- ## Description
正如我们在前面的示例中所看到的,对象可以包含嵌套对象和嵌套数组。与访问嵌套对象类似,可以链接数组括号表示法来访问嵌套数组。以下是如何访问嵌套数组的示例:
var ourPets = [
{
animalType:“猫”,
名称:[
“Meowzer”
“蓬松”,
“洁猫”
]
},
{
动物类型:“狗”,
名称:[
“点”,
“库巴”
“羊羊”
]
}
]。
ourPets [0] .names [1]; //“蓬松”
ourPets [1] .names [0]; //“Spot”
## Instructions
使用对象点和数组括号表示法从变量myPlants检索第二个树。
## Tests
```yml tests: - text: secondTree应该等于“松树” testString: 'assert(secondTree === "pine", "secondTree should equal "pine"");' - text: 使用点和括号表示法访问myPlants testString: 'assert(/=\s*myPlants\[1\].list\[1\]/.test(code), "Use dot and bracket notation to access myPlants");' ```
## Challenge Seed
```js // 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
```js console.info('after the test'); ```
## Solution
```js // solution required ```