title: Replace last N items in an array with JavaScript
body: <p>I'm trying to find the best way to replace the last N items in an array. I'm thinking of the following:</p>
  
  <p>Remove the N amount of items from the array:</p>
  
  <pre><code>arr = arr.slice(-N);
  </code></pre>
  
  <p>Add the needed values via array.push() doing an iteration to get to the number of needed insertions like so:</p>
  
  <pre><code>for(var i=0; i&lt;=N; i++) {
    arr.push(new value);
  }
  </code></pre>
  
  <p>Is there a more elegant solution to this?</p>
  
  <p>Thanks.</p>