简体   繁体   中英

How to get a value of an array that contains objects and arrays?

Im trying to get specific values from an array that is in another array. To be clear im using the Spotify Web API and want to get the name of the tracks of an playlist.

The array looks like that (Hope you can understand how it looks like^^) :

Object
tracks: Object
        items: Array [4]
               0: Object
                 track: Object
                        name
               1: Object
                 track: Object
                        name
               [...]

Now i have in my Ionic/Angular app the angular-spotify module and i was trying to get the name with the following code:

Spotify
.getPlaylist('User-ID', 'Playlist-ID')
.then(function (data) {
  console.log(data); 
  arrayLength = data.tracks.items.length;
  for (i = 0; i < arrayLength; i++) {
    alert(track[i]);
  }
});

But the console saying me that name isnt defined, where did i make the mistake?

您尚未定义track变量,因此可以在循环中定义它。

track = data.tracks.items[i];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM