im building a music player and im doing the artists, i already grouped the songs by artist, but now dont know how to print it, when i grouped i get this:
{"<unknown>": [{"artist": "<unknown>", "artwork": undefined, "cover": "", "duration": "5224", "genre": undefined, "id": "69", "title": "audio", "url": "file:////storage/emulated/0/Download/music/audio.mp3"}, {"artist": "<unknown>", "artwork": undefined, "cover": "/storage/emulated/0/.covers/a0549154236a4457dbbe7e8ecf845918", "duration": "221440", "genre": undefined, "id": "74", "title": "Plan-B-Si-no-le-Contesto", "url": "file:////storage/emulated/0/Download/music/Plan-B-Si-no-le-Contesto.mp3"}], "Bad Bunny": [{"artist": "Bad Bunny", "artwork": undefined, "cover": "/storage/emulated/0/.covers/a0549154236a4457dbbe7e8ecf845918", "duration": "158064", "genre": undefined, "id": "70", "title": "<3", "url": "file:////storage/emulated/0/Download/music/Bad Bunny - Gracias.mp3"}, {"artist": "Bad Bunny", "artwork": undefined, "cover": "/storage/emulated/0/.covers/a0549154236a4457dbbe7e8ecf845918", "duration": "251977", "genre": undefined, "id": "71", "title": "Callaita", "url": "file:////storage/emulated/0/Download/music/Bad-Bunny-Callaita.mp3"}], "Maluma": [{"artist": "Maluma", "artwork": undefined, "cover": "/storage/emulated/0/.covers/a0549154236a4457dbbe7e8ecf845918", "duration": "200229", "genre": undefined, "id": "73", "title": "Hawái", "url": "file:////storage/emulated/0/Download/music/Maluma-Hawai.mp3"}]},
as you can see, each artist is a property of the object, and it has an array that has object inside of it, each song is an object, how can i print it? each song by artist?
I'm assuming you got that data from an API, stored the result in a state variable (let's say data
). You can create local variable songs
and filter out all the songs from your object.
let songs=[];
Object.keys(data).forEach(artist=>data[artist].map(song=>songs.push(song)))
Then inside your render method you can output your songs using the map
method on songs
.
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.