I am having trouble displaying the artist's name on an overlay I created. How can I correctly target the code to access this information? Using data.artist[0].name is not producing the desired result.
// Fetching Album Information from the Spotify API to display on the overlay
function albumInformation(data){
var infoHTML = '<ul id="data">';
$.each(data.tracks, function(i, track){
infoHTML += '<li class="albumInfo">';
infoHTML += '<p>' + track.album.artists[0].name + '</p>';
infoHTML += '</li>';
}); // closes each
infoHTML += '</ul>';
$.getJSON(spotifyURL, albumData, albumInformation);
$(lightboxOverlay).append(infoHTML);
Information retrieved from Spotify API
{
"tracks" : [ {
"album" : {
"album_type" : "album",
"artists" : [ {
"external_urls" : {
"spotify" :
"https://open.spotify.com/artist/3WrFJ7ztbogyGnTHbHJFl2"
},
"href" : "https://api.spotify.com/v1/artists/3WrFJ7ztbogyGnTHbHJFl2",
"id" : "3WrFJ7ztbogyGnTHbHJFl2",
"name" : "The Beatles",
"type" : "artist",
"uri" : "spotify:artist:3WrFJ7ztbogyGnTHbHJFl2"
} ],
"available_markets" : [ "CA", "MX", "US" ],
"external_urls" : {
"spotify" : "https://open.spotify.com/album/0ETFjACtuP2ADo6LFhL6HN"
},
"href" : "https://api.spotify.com/v1/albums/0ETFjACtuP2ADo6LFhL6HN",
"id" : "0ETFjACtuP2ADo6LFhL6HN",