<div class="container"></div> <script> const buttons = [{ buttonId: 103676, link: "ww.google.com", }, { buttonId: 432549, link: "www.yahoo.com", }, ]; const createButton = ({ buttonId, link }) => { const a = document.createElement("a"); a.textContent = "first points"; a.href = link; a.setAttribute('data-id', buttonId); a.setAttribute('target', "_blank"); // open in new tab behvaiour return a; }; const container = document.getElementsByClassName("container")[0]; // P.S. you spelt container wrong in your id! buttons.forEach(button => container.appendChild(createButton(button))); </script>