title: How to add a new element to array in arrays in JavaScript
body: <p>I added 2 elements to my array in JavaScript and HTML,I want to add a copy to clipboard button as a new element to each array,but I am struggling to do this due to the complicated codes.
  here is my code</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var currImage = 0;
  window.onload = () =&gt; {
      const factsArr = [
   { image:'https://media.giphy.com/media/3o7aD5tv1ogNBtDhDi/giphy.gif', source:"&lt;a href='http://news.nationalgeographic.com/news/2010/03/100315-half-male-half-female-chickens/' style='text-decoration:none;color:#FFFFFF;' target='_blank'&gt;know more&lt;/a&gt;",},
   { image:'https://media.giphy.com/media/1nkUav308CBws/giphy.gif',      source:"&lt;a href='http://www.guinnessworldrecords.com/world-records/most-expensive-pizza' style='text-decoration:none;color:#FFFFFF;'target='_blank'&gt;know more&lt;/a&gt;"},
    ]:
    const swtch = () =&gt; {
      document.getElementsByClassName('image')[0].setAttribute('src', factsArr[currImage].image);
      document.getElementsByClassName('source')[0].innerHTML=factsArr[currImage].source;
   document.getElementById('copyToClipboard').innerHTML=copyToClipboard(element).copyToClipboard
      currImage++;
      if (currImage == factsArr.length)
          currImage = 0;
      console.log(currImage);
  };
  document.getElementsByClassName('generate-btn')[0].addEventListener('click', swtch);
  document.getElementsByClassName('source')[0].addEventListener('click', swtch);
  }
  function copyToClipboard(element) {
    var $temp = $("&lt;input&gt;");
    $("body").append($temp);
    $temp.val($(element).text()).select();
    document.execCommand("copy");
    $temp.remove();
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;button class="generate-btn"&gt;Amazing Fact Button&lt;/button&gt;
  &lt;div class="source"&gt;&lt;/div&gt;
  &lt;img class="image" /&gt;
  &lt;button onclick="copyToClipboard('element')"&gt;Copy Link&lt;/button&gt;</code></pre>
  </div>
  </div>
  </p>