Skip to content Skip to sidebar Skip to footer

How Make A Loop Array Youtube Videos?

I want to loop this video list with image attached: when the last video ends the first one of the list starts, how is it possible to do it? var tag = document.createElement('script

Solution 1:

You may try this. We are starting by creating array of objects first. Then we need to iterate and restrict iterator according to length of our array.

const videos = [
    {id : 'RGpr3Y6Q-1M', img : 'image1.png'},
    {id : 'btxdcqLOGuc', img :  'mage2.png'},
   {id:  'CIx0a1vcYPc' , img :  'mage3.png'},
   {id :  '6-4KydP92ss' , img : 'mage4.png'} 
];

  var num =-1 ; 
  
  pickTheVideo =(  )=>{
    num = num + 1if( num > videos.length -1  ){   num =-1  ;  return ( pickTheVideo( ) ) }
    
    return videos[ num ]
    
  }
 
for (let index = 0; index < 10   ; index++) {
    const videoObj = pickTheVideo() ;
    console.log( index , "videoObj" , videoObj )
}

Post a Comment for "How Make A Loop Array Youtube Videos?"