Jammming: Unhandled Rejection (TypeError): Cannot read property '0' of undefined

Finishing up the Jammming project and typed in a search and the following showed up:

{{ Unhandled Rejection (TypeError): Cannot read property ‘0’ of undefined

(anonymous function)

src/util/Spotify.js:44

  41 | return jsonResponse.tracks.items.map(track => ({  42 |   id: track.id,  43 |   name: track.name,> 44 |   artist: track.artist[0].name,     | ^  45 |   album: track.album.name,  46 |   uri: track.uri  47 | }));

View compiled

(anonymous function)

src/util/Spotify.js:41

  38 | if (!jsonResponse.tracks) {  39 |   return [];  40 | }> 41 | return jsonResponse.tracks.items.map(track => ({     | ^  42 |   id: track.id,  43 |   name: track.name,  44 |   artist: track.artist[0].name,

View compiled

This screen is visible only in development. It will not appear if the app crashes in production.
Open your browser’s developer console to further inspect this error. Click the ‘X’ or hit ESC to dismiss this message.
}}

Hey @charleskallick4619, The error message is basically saying that track.artist is undefined. You are using track.**artist** instead of track.artist**s**. Also, the instructions say "Artist - returned as track.artist**s**[0].name.

I hope this will help you!

2 Likes

Should be using console.log() to debug/check your code if you get stuck and compare with what you are expecting to see.

https://www.codecademy.com/courses/javascript-errors-debugging/lessons/debugging-code/exercises/console-log-debugging-ii

1 Like

got it taken care of. thank you!