--- id: 56533eb9ac21ba0edf2244cd title: Acessar arrays aninhados challengeType: 1 videoUrl: 'https://scrimba.com/c/cLeGDtZ' forumTopicId: 16160 dashedName: accessing-nested-arrays --- # --description-- Como vimos em exemplos anteriores, objetos podem conter tanto objetos aninhados quanto arrays aninhados. Semelhante ao acesso de objetos aninhados, a notação de colchetes pode ser encadeada para se acessar arrays aninhados. Aqui está um exemplo de como se acessar um array aninhado: ```js var ourPets = [ { animalType: "cat", names: [ "Meowzer", "Fluffy", "Kit-Cat" ] }, { animalType: "dog", names: [ "Spot", "Bowser", "Frankie" ] } ]; ourPets[0].names[1]; ourPets[1].names[0]; ``` `ourPets[0].names[1]` seria a string `Fluffy` e `ourPets[1].names[0]` seria a string `Spot`. # --instructions-- Usando a notação de ponto e de colchetes, defina a variável `secondTree` para o segundo item na lista de `trees` do objeto `myPlants`. # --hints-- `secondTree` deve ser igual à string `pine`. ```js assert(secondTree === 'pine'); ``` Seu código deve usar notação de ponto e colchetes para acessar `myPlants`. ```js assert(/=\s*myPlants\[1\].list\[1\]/.test(code)); ``` # --seed-- ## --after-user-code-- ```js (function(x) { if(typeof x != 'undefined') { return "secondTree = " + x; } return "secondTree is undefined"; })(secondTree); ``` ## --seed-contents-- ```js var myPlants = [ { type: "flowers", list: [ "rose", "tulip", "dandelion" ] }, { type: "trees", list: [ "fir", "pine", "birch" ] } ]; var secondTree = ""; ``` # --solutions-- ```js var myPlants = [ { type: "flowers", list: [ "rose", "tulip", "dandelion" ] }, { type: "trees", list: [ "fir", "pine", "birch" ] } ]; var secondTree = myPlants[1].list[1]; ```