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 AJAX Basics (retiring) AJAX and APIs Displaying the Photos

Pedro Cabezas
Pedro Cabezas
9,646 Points

Uncaught TypeError: Cannot read property 'length' of undefined

I am having problem with this code. I thought is was a syntax error on my end but even the instructors file generates the same error in the JavaScript console when clicking one of the buttons. "Uncaught TypeError: Cannot read property 'length' of undefined". I verified the source of the photos is still there but this error doesn't give me any details on whats wrong other than to look at line 2 of the code which has nothing. The data is already in json format but this error seems to be about something related. Can someone help. Thanks.

It dose not clear what code you talking about. Anyway, here some ideas: Objects don't have a .length property. Try out something like Object.keys(myObject).length and provide us with a code, please.

2 Answers

jobbol
seal-mask
.a{fill-rule:evenodd;}techdegree
jobbol
Full Stack JavaScript Techdegree Student 16,610 Points

Cannot read property of undefined.

In English, means you've tried to access something that doesn't exist. This can happen when:

  • You made a typeo on an object name. JS is case sensitive.
  • You tried accessing keyword this but it points to the wrong object.

An additional code post would be needed to debug your problem more, otherwise kudos if this helped you.

Pedro Cabezas
Pedro Cabezas
9,646 Points

Thanks for responding guys. Sorry there is no picture but I'm looking everywhere and I don't see an option to upload or insert a picture. I was hoping you guys could download the instructors files real quick and see for yourselves.

My only assumption is what Josh states that the source does not exist anymore because it can't be the code. I'm using the code the instructor uploaded and his file also generates the same issue. If there was any errors with his code I'm sure others would be inquiring about this same thing. The URL however seems to be valid because when I enter it in the browser the objects load so then it goes right back to wondering if it might be the code.

I guess I'll move on and maybe figure it out with the project in the next vid but if anyone one else has any ideas please let me know.. Thanks.