Problem with Accessing Nested Arrays

Tell us what’s happening:
Hello, can you help me understand what i’m doing wrong?

Thank you

Your code so far


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


var secondTree = myPlants[2].list[2]; 

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays/

As you must have learnt in previous examples, arrays are zero-indexed.

For example i have an array:

var arr = [1,2,3,4,5]

So, to access the first element that is 1, we will use arr[0] and to get the second element that is 2,
we use arr[1].

Hope this helps.

1 Like