javascript – Insert element type date in an array every determined number of elements

I am trying to insert a string which is a date every 5 elements that are generated dynamically.

let ul = document.createElement ('ul');
        
  for (let i = 0; i <items.length; i ++) {
      let element = this.createItemSms (items[i]);

      if ((i% 5 == 0)) {
          let date = `

$ {this.allDatesRange[i]}

`;           ul.insertAdjacentHTML ('beforeend', date);       }       ul.appendChild (element);   }   return container.appendChild (ul);      createItemSms (item) {         return utils.createElement (`
  • $ {item.fcTitle}

  • `);    }

    The problem is that this.allDatesRange[] is a variable of type array whose length does not correspond to the length that the for runs. Therefore it only shows the first element correctly and the others only shows undefined . Any comments or help is welcome, thank you.