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

How to access nameless objects in an array

Hey. I’m dealing with a database that I have to fetch Json country data and then parse it. However the country data is an array of nameless objects. Now I’ve scrolled through it, found the index, and then parsed it and that seemed to work fine, but the problem is when a new country is added it throws the index off (if the index for the US is 45 and something gets added above it it becomes 46). So that means I have to update the code each time something is added. Is there a better way of targeting a nameless object in an array?

Thanks in advance

1 Answer

tomd
tomd
16,701 Points

Could you post your code? Its a little difficult to debug otherwise.

It's alright Thankfully I've found out how to do it. Here is how to do it for anyone that is interested.

http://w.trhou.se/68y6qwt9xc