-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnested_arrays_json.js
59 lines (52 loc) · 1.01 KB
/
nested_arrays_json.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//ACCESSING NESTED ARRAYS IN JSON
/*
As we have seen in earlier examples, JSON objects can contain both
nested objects and nested arrays. Similar to accessing nested objects,
Array bracket notation can be chained to access nested arrays.
Here is an example of how to access a nested array:
var ourPets = [
{
animalType: "cat",
names: [
"Meowzer",
"Fluffy",
"Kit-Cat"
]
},
{
animalType: "dog",
names: [
"Spot",
"Bowser",
"Frankie"
]
}
];
ourPets[0].names[1]; // "Fluffy"
ourPets[1].names[0]; // "Spot"
*/
//INSTRUCTIONS
/* Retrieve the second tree from the variable myPlants using object
dot and array bracket notation. */
// Setup
var myPlants = [
{
type: "flowers",
list: [
"rose",
"tulip",
"dandelion"
]
},
{
type: "trees",
list: [
"fir",
"pine",
"birch"
]
}
];
// Only change code below this line
var secondTree = myPlants[1].list[1]; // Change this line
console.log(secondTree);