There are at least two ways in JavaScript to change an image:
Using the setAttribute() method.
img.setAttribute('src', 'imgs/' + imgs[i] + '.png');
Writing the src.attribute of the image-element directly.
img.src = 'imgs/' + imgs[i] + '.png'
Both ways work. I've tried it out.
But:
Should I prefer one way over the other and why? Or does it matter at all and I can use what I personally prefer?