title: Move elements from one array to another and display value of both arrays at the same time
body: <p>(Javascript) How do I move elements from one array to another in random order on click of a button and also display elements in both the arrays at the same time?</p>
  <p>For example the desired output is :</p>
  <p>Elements in array1 : 1,2,3,4,5
  <br>Elements in array2 : -</p>
  <p><strong>BUTTON</strong></p>
  <p>now on clicking the button</p>
  <p>Elements in array1 : 1,2,4,5
  <br>Elements in array2 : 3</p>
  <p><strong>BUTTON</strong></p>
  <p>now on clicking the button</p>
  <p>Elements in array1 : 2,4,5
  <br>Elements in array2 : 3,1</p>
  <p><strong>BUTTON</strong></p>
  <p>now on clicking the button</p>
  <p>Elements in array1 : 2,5
  <br>Elements in array2 : 3,1,4</p>
  <p><strong>BUTTON</strong></p>
  <p>and so on...</p>
  <p>This is what i got from another stackoverflow user.</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>let array1 = [1, 2, 3, 4, 5]
  document.getElementById("btn").onclick = () =&gt; { 
    let num = array1[Math.floor(Math.random()*array1.length)]
    const index = array1.indexOf(num); 
    if (index &gt; -1) {
       array1.splice(index, 1); 
       alert("You chose: " + num + "\nArray: " + array1)
    } else {
      alert("No numbers remaining.") 
    }
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;button id="btn"&gt;Get Random Number&lt;/button&gt;</code></pre>
  </div>
  </div>
  </p>