var count = example.array.length; // Выводит 5 элементов
<div class='dots-wrapper'></div>
<div class='dots-wrapper'>
<div class='dot'></div>
<div class='dot'></div>
<div class='dot'></div>
<div class='dot'></div>
<div class='dot'></div>
</div>
const container = document.querySelector('.dots-wrapper');
const tag = 'div';
const className = 'dot';
const count = 10;
const elementHTML = `<${tag} class="${className}"></${tag}>`;
const elementsHTML = Array(count).fill(elementHTML).join('');
// или
const elementsHTML = Array(count + 1).join(elementHTML);
// или
const elementsHTML = elementHTML.repeat(count);
container.innerHTML = elementsHTML;
// или
container.insertAdjacentHTML('beforeend', elementsHTML);
for (let i = 0; i < count; i++) {
const element = document.createElement(tag);
element.classList.value = className;
container.insertAdjacentElement('beforeend', element);
}
while (container.children.length < count) {
const element = document.createElement(tag);
element.classList.add(className);
container.appendChild(element);
}
const element = document.createElement(tag);
element.className = className;
container.append(...Array.from({ length: count }, () => element.cloneNode()));