https://www.freecodecamp.cn/challenges/accessing-nested-arrays-in-json
使用点操作符和中括号操作符来检索变量myPlants
的第二棵树。
代码如下:
// 初始化变量
var myPlants = [
{
type: "flowers",
list: [
"rose",
"tulip",
"dandelion"
]
},
{
type: "trees",
list: [
"fir",
"pine",
"birch"
]
}
];
var secondTree = myPlants[1].list[1];
运行结果 secondTree = pine