title: How do I iterate over a queue, adding and deleting elements as I go?
body: <p>I want to be able to iterate over a queue, each time adding some new elements to the queue, but removing elements that I have dealt with.</p>
  
  <pre><code>queue = [[0,8],[1,2],[2,4]]
  
  for [x,y] in queue
      for i in [1,2,3]
          # Do something that results in a new coordinate..
          queue.push([newx,newy])
  </code></pre>
  
  <p>The problem is, I am not sure what the best way to do this would be.</p>
  
  <p>If I delete each element from the array as I iterate, it leaves an empty element in the array.</p>
  
  <p>If I copy the array, empty it by doing <code>queue.length = 0</code> and then iterate over the copy, that won't work because doing a slice to copy doesn't work when the array contains objects.</p>
  
  <p>What would be the correct way to do this?</p>