I want to loop through images in a subfolder named images. The purpose is to append them to an image bar in my html .
The solution I came up with was to pull out the images form the subfolder and put them in an array
const imgArray= ['pic1.jpg', 'pic2.jpg', 'pic3.jpg' , 'pic4.jpg', 'pic5.jpg'];
and then loop through the array
for (let i = 0; i <= imgArray.length-1; i += 1) {
const newImage = document.createElement('img');
newImage.setAttribute('src', imgArray[i] ) ;
imageBar.appendChild(newImage);}
Is there a way to set a variable as the path to the image folder and then just loop through the folder. Maybe something like:
for ( let i=0; i<= imageFolder.length -1; i++){
const newImage = document.createElement('img');
newImage.setAttribute('src', imgFolder[i] ) ;
thumbBar.appendChild(newImage)}