Accessing an array's object's property, how?

The curriculum covers accessing nest objects, but it presented what they called complex objects wit han exemple of an array containing objects. Now i learned from this forums some answers about accessing object’s array’s entriee it was easy. Now the table has turned, it’s the array that is containing the object. How to access an object’s value if that object is in an array?
@snowmonkey any hints ?
Thank you.

What have you tried so far?
You know how to access items in an array. If it’s an array of objects, then that will give you an object. You know how to access object properties.

1 Like

Say we have an array of books, might look like:

const library=[
  { title: "Ishmael", author: "Daniel Quinn"},
  { title: "The BFG", author: "Roald Dahl"}
]

Now, if we wanted, we could go:

const faveBook=library[1];
console.log(faveBook.author)

We have made faveBook a reference to the second element in library, and we can treat it as any other object.

Well, what if we got rid of faveBook? Is there any reason we couldn’t use library[1] as the object reference, and simply get our properties straight from that??

Give it a try, let me know what happens!

Edit: what @ArielLeslie said, quicker and better than me. :grin:

1 Like

I would also review this lesson from the curriculum.

Practicing with these examples will help when you get to the record collection challenge.

1 Like

I tried them both, they both worked. You just put one bracket after the other wether an array is containing the object or vice versa, just have to respect the order. I was afraid to do what i learned before and get weird displays in the console and get lost. So i came here again.
Thanx alot.

1 Like