I am trying to create a string of the artist's names from the artists array shown below (i.e. "Taylor Swift, Rihanna, Justin Timberlake"), but the artist_obj is undefined and I get the error "TypeError: Cannot read property 'name' of undefined". How do I fix this?
Code
//Get info for each song
var artists = item["artists"],
artist = "";
var artists_count = 0;
artists.forEach(function(item) {
var artist_obj = item["artists_count"];
if(artists_count !== 0) {
artist = artist + ", " + artist_obj["name"];
} else {
artist += artist_obj["name"];
}
artists_count++;
});

var artists = item["artists"], artist = "";It would set your artists array to null, so everything you try to get from it would return undefined.