<div class="box">
<div class="parent">
<div class="child">1</div>
<div class="child">2</div>
<div class="child">3</div>
</div>
<hr>
<div class="parent">
<div class="child">10</div>
<div class="child">20</div>
<div class="child">30</div>
</div>
<hr>
<div class="parent">
<div class="child">5</div>
<div class="child">10</div>
<div class="child">15</div>
</div>
</div>
<script>
let arr = [4, 40, 20];
for(let i = 0; i < arr.length; i++) {
$('.parent').append(
'<div class="child">' + arr[i] + '</div>'
);
}
</script>
<div class="box">
<div class="parent">
<div class="child">1</div>
<div class="child">2</div>
<div class="child">3</div>
<div class="child">4</div>
</div>
<hr>
<div class="parent">
<div class="child">10</div>
<div class="child">20</div>
<div class="child">30</div>
<div class="child">40</div>
</div>
<hr>
<div class="parent">
<div class="child">5</div>
<div class="child">10</div>
<div class="child">15</div>
<div class="child">20</div>
</div>
</div>
document.querySelectorAll('.parent').forEach((n, i) => {
n.insertAdjacentHTML('beforeend', `<div class="child">${arr[i]}</div>`);
});
for (const [ i, n ] of document.querySelectorAll('.parent').entries()) {
n.append(document.createElement('div'));
n.lastChild.className = 'child';
n.lastChild.innerText = arr[i];
}
arr.forEach(function(n, i) {
const div = document.createElement('div');
div.classList.add('child');
div.textContent = n;
this[i].appendChild(div);
}, document.getElementsByClassName('parent'));
$('.parent').append(i => `<div class="child">${arr[i]}</div>`);