How could I display the first image in array?

My array is just not displaying anything

var imgArray = new Array();

imgArray[0] = new Image();
imgArray[0].src = "";

imgArray[1] = new Image();
imgArray[1].src = "";

function nextImage() {
    var createImg = document.createElement("img");
    createImg.src = imgArray[0];

I put comments in a pen I made based on your code. You can find the pen here.

1.) In your code, you tried to define the createImg.src as the first Image object (technically it’s an HTMLImageElement) in the array instead of that Image object’s src. You can read more about the Image element here.

2.) Don’t forget to call the function that you defined.

I hope this helps you!

1 Like

thanks alot was very handy