Link Search Menu Expand Document

Accessing Nested Arrays

Summary

  • Array bracket notation can be chained to access nested arrays.

Final Code

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

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