Tell us what’s happening:
I have just finished Basic JavaScript: Accessing Nested ArraysPassed and was wondering if objects in the array can given a name like for example an object with a nested object
var object = {
**prop1:** {
albumTitle: 'Slippery When Wet',
artist: 'Bon Jovi',
tracks: ['Let It Rock', 'You Give Love a Bad Name']
},
**prop2:** {
albumTitle: '1999',
artist: 'Prince',
tracks: ['1999', 'Little Red Corvette']
}
}
vs
Your code so far
// Setup
var myPlants = [
**no name for the objects**{
type: "flowers",
list: [
"rose",
"tulip",
"dandelion"
]
},
{
type: "trees",
list: [
"fir",
"pine",
"birch"
]
}
];
// Only change code below this line
var secondTree = ""; // Change this line
Is it because of the way array are accessed? U use numbers to access them so I guess it wouldn’t be a point. But if that is the case wouldn’t it be better to just use objects with nested objects over Arrays because you have the title that can help you know what you are accessing?
Could you give an example of when you would used an Array with nested objects over an object with nested objects?
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
.
Challenge: Accessing Nested Arrays
Link to the challenge: