Question

I'm trying to get a list of related artists but am returning mixed results. Sometimes the name of the related artist will appear and sometimes it will return "undefined".

How do I retrieve the names of all the related artists without getting an "undefined" result?

       models.Artist
          .fromURI('spotify:artist:7hJcb9fa4alzcOq3EaNPoG')
          .load(artist_properties)
          .done(function(artist){

            artist.related.snapshot().done(function(r){

              var relatedArtists = r.toArray();
              var relatedArtistsNames = [];
              var i;

              for(i = 0; i < relatedArtists.length; i++){
                var listItem = document.createElement("li");
                listItem.innerHTML = relatedArtists[i].name;
                $('#relatedContainer').append(listItem);
              }
            });
          });

This outputs:

enter image description here

Was it helpful?

Solution

From your next question, I'd say you already figured out snapshot.loadAll('name'), but I'll throw it on here for posterity.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top