Please tell me how do I get that AllMainSongsIndex out from the loop and how do I use it
songsItems.forEach((element, i) => {
let Allcovers = element.querySelectorAll(".cover")
Allcovers[0].src = songs[i].coversPath
let AllNames = element.getElementsByClassName("Names");
AllNames[0].innerHTML = songs[i].songName;
let AllMainSongsIndex=element.querySelector(".currentsoundGIF").id;
return AllMainSongsIndex;
});
Thank you in advanced
Define it outside the loop, assign inside the loop and use it outside the loop. But it's confusing about which one you want to use, may be use some logic to use a particular value, in your case the last loop element will get assigned.
let AllMainSongsIndex= "";
songsItems.forEach((element, i) => {
let Allcovers = element.querySelectorAll(".cover")
Allcovers[0].src = songs[i].coversPath
let AllNames = element.getElementsByClassName("Names");
AllNames[0].innerHTML = songs[i].songName;
AllMainSongsIndex=element.querySelector(".currentsoundGIF").id;
});
// Use it here