title: Is there a way to update an existing array on a button click in Javascript/HTML?
body: <p>So I have an issue (consisting of mainly Javascript). The basis of what I would like is a button in HTML which triggers a Javascript function to update an existing array with a specific scalar each time the button is pressed.</p>
  
  <p>The code I have so far is this:</p>
  
  <p>HTML Side: <code>&lt;button type="button" onclick="scalar()"&gt;Click Me!&lt;/button&gt;</code></p>
  
  <p>Javascript Side:</p>
  
  <pre><code>let data = [10, 20];
  
  function scalar() {
      for (i=0; i&lt;data.length; i++)
          data[i] *= 5;
      }
  
      alert(data);
  }
  </code></pre>
  
  <p>What I expect this to do is when I press the button for the first time, it would update the array <code>data</code> to be <code>[50, 100]</code>. Next time I press it it updates <code>data</code> to <code>[250, 500]</code>. However, this does not work properly for some reason (I added the <code>alert(data)</code> to see what was in the array <code>data</code> on button press).</p>
  
  <p>Any help would be greatly appreciated! Thanks.</p>