Append img if img id doesnt exist

I have a function that append img elements to a div (gridTwo). It is called by another function.

If there already is a img element of that name or data-id in the gridTwo div, i dont want to add another element.
Is there anything I can add to the if statement to stop the function to add duplicates?

Heres my function:

function wonCards() {
    for (let j = 0; j < cardsWonMerged.length; j++) {
        for (let i = 0; i < cardArraySingles.length; i++) {
            if (cardsWonMerged[j] == cardArraySingles[i].name) {
            const card = document.createElement('img')
            card.setAttribute('src', cardArraySingles[i].img)
            card.setAttribute('dataTwo-id', i)
            card.setAttribute('name-id', cardArraySingles[i].name)
            gridTwo.append(card)
            }
        }
    }
}