<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()) {
const div = document.createElement('div');
div.className = 'child';
div.textContent = arr[i];
n.append(div);
}
$('.parent').append(i => `<div class="child">${arr[i]}</div>`);