Task Using dot and bracket notation, set the variable
secondTree to the second item in the
trees list from the
Why cant I use [bracket][bracket] notation here (besides the challenge saying to use [bracket].dot notation)?
I thought [bracket][bracket] notation was valid but my log is returning undefined here…
const myPlants = [
const secondTree = myPlants;
Your browser information:
User Agent is:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0
Link to the challenge:
myPlants is an array so you can say myPlants to get the 2nd item in the array
But the second item in the array is an object
and that object does not have a property called 1
If you observe the data in myPlants you can see that it is
- an array of two objects
- each objects consists of keys: type and list
- type is string and list is a array of items.
If you want to get second item in the array list whose type is ‘trees’ then
- var tempObj = myPlant will return a object which having type=“trees”
- Now tempObj having keys: type and list. You should select list by using dot notation tempObj.list and second item using bracket notation tempObj.list.
Final output will be myPlant.list