Seems simple enough:
const downloadFile = function(url, filename){
const link = document.createElement("a");
link.href = url;
link.download = filename;
link.target = "_blank";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
link = null;
};
const data1 = [
{ href: "...", name: "...", song: "..." },
{ href: "...", name: "...", song: "..." }
];
const playlist1 = document.getElementById('playlist1');
data1.forEach((item, index) => {
const li = document.createElement("li");
li.setAttribute("id", `li-items-${index}`);
const span = document.createElement("span");
span.classList.add("dwn", "fa", "fa-download");
span.dataset.song = item.song;
span.textContent = item.name;
span.addEventListener("click", () => downloadFile(item.href, item.song));
li.appendChild(span);
playlist1.appendChild(li);
});
Array.prototype.forEach() - JavaScript | MDN[
^]
EventTarget.addEventListener() - Web APIs | MDN[
^]