title: Is there a way to combine map and shift in Javascript?
body: <p>I'm working with a buffer array that I am periodically checking. When I am mapping through the elements, I would like access the element using the shift method, this way I would get the next element in the array and would also remove it. Is there a way to do this in a map? Thank you!</p>
  
  <p>I currently have a naive solution, which is prone to race conditions.</p>
  
  <pre><code>if (timestep) {
      bufferArray.map((mvt) =&gt;{
          console.log(mvt)
      });
      bufferArray = [];
  } 
  </code></pre>