'How print a loop inside of sweet alert window

I want to loop an array and show the result using sweet alert, I am new in this so I try the code below, but show me some like [object],[object]

swal({
  content:{
    element: "ul",
    attributes: {
      innerHTML:$.each(json.DATA.ARYPUB, function (key, img) {
                      "<li><img src='"+img.PATH+"'></li>"
       })
    }
  }
})

Can someone help me, please



Solution 1:[1]

One approach could be generating the complete HTML outside the constructor of the alert and then set that html string to the related property. Example:

var html = "";

$.each(json.DATA.ARYPUB, function(key, img)
{
    html += "<li><img src='" + img.PATH + "'></li>"
});

swal({
    content:{
        element: "ul",
        attributes: {
            innerHTML: html
        }
    }
});

Solution 2:[2]

I faced the same issue so, I did this

const addOption = (arr) => {
  let optionItems;
  arr.forEach(item =>{

    optionItems += `<option value="${item}">${item}</option>`
  })
  return optionItems
}

//in swal 

 Swal.fire({
    html:addOption(Yourarray) 
    })

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shidersz
Solution 2 Mohamed Jawad