title: How do I delete the first N items from an ES6 Map object without recreating the Map?
body: <p>Say I want to delete the first 100 entries of a Map without recreating the map, and also do this in the most efficient way.</p>
  
  <p>Let's say you have a <strong>500 item <a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Map" rel="nofollow noreferrer">ES6 Map Object</a></strong>:</p>
  
  <pre><code>let map = new Map(... 500 items)
  </code></pre>
  
  <p>Currently I do it like this:</p>
  
  <pre><code>const newCache = new Map(
    Array.from(map).slice(100)
  )
  
  map.clear()
  
  map = newCache
  </code></pre>
  
  <p>But this recreates the Map.</p>
  
  <p>The other way is to run over the first 100 keys:</p>
  
  <pre><code>Array.from(map.keys())
       .slice(0, 100)
       .forEach(key =&gt; map.delete(key))
  </code></pre>
  
  <p>But it looks inefficient.</p>