Javascript/Node.JS forEach loop with Count

I have a forEach loop which displays all records for ‘communities’. For every 10th record, I want to insert an ‘advert record’, then continue with the loop of ‘communities’.

With my existing code, although the ‘advert record’ is displayed at record 10, I’ve found that ‘communities record 10’ is being skipped/missed out, so it looks like this:
R1 – R2 – R3 – R4 – R5 – R6 – R7 – R8 – R9 – ADVERT AT 10 – R11 – R12

Whereas what I want is this:
R1 – R2 – R3 – R4 – R5 – R6 – R7 – R8 – R9 – ADVERT AT 10 – R10 – R11

Can someone please advise where my code is going wrong?

    <div class="index-record-grid-container" id="communityGroupsContainer">
        <% let count = 0; %>
        <% communities.forEach(function(community, i) { %>
            <% count = count+1; %>
            <% if (count === 10) { %>
                <div class="standard-record-container">
                    <div class="standard-ad-container">
                        <h3 class="standard-ad-header">Advertisement</h3>
                        <% promotions.slice(1,2).forEach(promotion => { %>
                            <img class="standard-ad-image lazy" data-src="https://res.cloudinary.com/dcjceb5aj/image/upload/w_400,c_fit,q_auto,f_auto,fl_lossy/<%- promotion.images[0].public_id %>"> 
                        <% }) %> 
                    </div>
                </div>
            <% } else if (count === 20) { %>
                <div class="standard-record-container">
                    <div class="standard-ad-container">
                        <h3 class="standard-ad-header">Advertisement</h3>
                        <% promotions.slice(1,2).forEach(promotion => { %>
                            <img class="standard-ad-image lazy" data-src="https://res.cloudinary.com/dcjceb5aj/image/upload/w_400,c_fit,q_auto,f_auto,fl_lossy/<%- promotion.images[0].public_id %>"> 
                        <% }) %> 
                    </div>
                </div>
            <% } else { %>
                <div class="standard-record-container">
                    <div class="record-grid-container">
                        <div class="box-record-username-row-2">