title: How can I add new array elements at the beginning of an array in JavaScript?
body: <p>I have a need to add or prepend elements at the beginning of an array.</p>
  <p>For example, if my array looks like below:</p>
  <pre><code>[23, 45, 12, 67]
  </code></pre>
  <p>And the response from my AJAX call is <code>34</code>, I want the updated array to be like the following:</p>
  <pre><code>[34, 23, 45, 12, 67]
  </code></pre>
  <p>Currently I am planning to do it like this:</p>
  <pre><code>var newArray = [];
  newArray.push(response);
  
  for (var i = 0; i &lt; theArray.length; i++) {
      newArray.push(theArray[i]);
  }
  
  theArray = newArray;
  delete newArray;
  </code></pre>
  <p>Is there a better way to do this? Does JavaScript have any built-in functionality that does this?</p>
  <p>The complexity of my method is <code>O(n)</code> and it would be really interesting to see better implementations.</p>