javascripthtmlcssbootstrap-4react-scripts

How to dynamically generate images and display after the webpage loads in javaScript?


I want to images from an array and upon onload of the browser window it gets display on the webpage. this is what I did.

const players = [
    {
     photo: 'img/photo0.jpeg'
    },
    {
     photo: 'img/photo1.jpeg'
    },
    {
     photo: 'img/photo2.jpeg'
    }]

// This is the function I built to do that.
    function() {

      for(i = 0; i < players.lengh; i++;){
      }
    }

Solution

  • You could access to the onLoad method through the window object.

    window.onload = function() {
      // Whatever you want to do on load
    };