[
{
"albumTitle": "Meteora",
"artist": "Linkin Park",
"tracks": [
{"title": "Breaking The Habit", "src": "meteora/breaking-the-habit.mp3"},
{"title": "Track 2", "src": "meteora/track-2.mp3"},
{"title": "Track 3", "src": "meteora/track-3.mp3"},
]
},
{
"albumTitle": "Сборник",
"tracks": [
{"title": "Track 1", "artist": "Газманов", "src": "trash/track-1.mp3"},
{"title": "Track 2", "artist": "Киркоров", "src": "trash/track-2.mp3"},
{"title": "Track 3", "artist": "Шуфутинский", "src": "trash/track-3.mp3"},
]
}
]
const onClick = ({ target }) => {
const { title, artist } = target.dataset;
actualTitle.innerText = title;
actualArtist.innerText = artist;
};
document.querySelector(".albums-wrapper").addEventListener("click", onClick);
let visibleAlbum = "";
let album = "";
let albumImage = "";
function showPlaylist(visibleAlbum) {
for (let i = 0; i < visibleAlbum.length; i++) {
let trackContainer = document.createElement("div");
trackContainer.classList.add("track");
let trackName = document.createElement("p");
trackName.classList.add("track-name");
trackName.innerText = visibleAlbum[i].name;
let trackArtist = document.createElement("p");
trackArtist.classList.add("track-artist");
trackArtist.innerText = visibleAlbum[i].artist;
let mainTrack = document.createElement("audio");
mainTrack.classList.add("main-track");
mainTrack.setAttribute("src", `files/${visibleAlbum[i].src}.mp3`);
trackContainer.append(mainTrack);
trackContainer.append(trackName);
trackContainer.append(trackArtist);
playlist.append(trackContainer);
trackContainer.addEventListener("click", () => {
mainTrack.play();
});
}
}
По сути не обязательно json обратно в объект преобразовывать
Я могу имя альбома и так достать, к примеру
А значит и все остальное.