Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects The Build an Object Challenge, Part 2 Solution

Alex Flores
Alex Flores
7,864 Points

Accessing objects in arrays a bit different?

I just want to confirm this... So when I'm accessing the value of a property (of an object) inside an array, I just do for example... console.log(arrayName.propertyName)

However, if I'm just trying to access the value of an object that ISN'T inside an array, I do for example... console.log(objectName[property].

So that's the only difference in syntax, the bracket.

1 Answer

If you are trying to access an object that is inside an array you would do

arrayName[indexOfObjectInSideArray].propertyName

otherwise you would just do objectName.propertyName

For instance if you had an var arr = [{ propOne : 'hello' }];

You would do arr[0].propOne to access 'hello'