title: Why does the pop() method stop working when used within a map method?
body: <p>I want to reverse an array in place without using reverse method. I tried the following 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>function reverseArray(arr) {
    return arr.map(() =&gt; {
      return arr.pop()
    })
  }
  console.log(reverseArray([1, 2, 3, 4]));
  //logs [4,3,undefined,undefined]</code></pre>
  </div>
  </div>
  </p>
  <p>Using dev tools debugger, this is what logs in the console: <code>(4) [4, 3, empty × 2]</code>.</p>
  <p><code>arr.pop()</code> returns undefined if called on an empty array but it shouldn't be empty in this case, to my understanding.</p>
  <p>Question: what's happening? Why are the first two elements printing correctly and the rest aren't?</p>