title: Do Javascript Maps have a set amount of keys that they can set or do they have a set amount of key operations that can be done?
body: <p>So I know that Javascript Maps have a set amount of keys that they can store ( around 16.7 M ).</p>
  <p>I was trying to test if I can ( in a very ugly way ) remove the oldest elements from the array. I noticed that no matter what I do it is actually not the Map size that was a limiting factor but it was rather the amount of operations I have done that were limiting me.</p>
  <p>Below is an example 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>const map = new Map();
  let i = 0;
  
  while (true) {
    i++;
  
    set(i, i);
  
    if (i % 1000 === 0)
      console.log('INSERTED: ', i, 'KEYS', 'MAP SIZE :', map.size);
  }
  
  function set(key, value) {
    if (map.size &gt; 16770000) {
      Array.from(map.keys()).slice(0, 10000).forEach(key =&gt; map.delete(key));
      console.log('DELETED, current map size:', map.size);
    }
  
    try {
      map.set(key, value);
    } catch (e) {
      console.log('MAP SIZE:', map.size, 'INSERTED:', key);
      throw e;
    }
  }</code></pre>
  </div>
  </div>
  </p>
  <p>When you run the snippet, just check your console. What you should notice is at the end ( when the exception is thrown ) you will get the Map Size and the INSERTED. Map Size will be a variable ( depending on how many elements you remove, which in this case is 10000) but INSERTED will always be the same value. So how come if I am not reaching the limit of the Map.... I am somehow reaching a limit. Is this some kind of reference issue that I am missing?</p>
  <p>EDIT: As mentioned by @CRice if you increase the items deleted to around 10,000,000 then the cycle continues on seemingly forever.</p>
  <p>EDIT 2: Here is an answer from one of the V8 devs talking about the limit of 16.7M keys: <a href="https://stackoverflow.com/a/54466812/5507414">https://stackoverflow.com/a/54466812/5507414</a></p>
  <p>EDIT 3: See answer: <a href="https://stackoverflow.com/a/63234302/5507414">https://stackoverflow.com/a/63234302/5507414</a>. We still need a V8 developer or someone with further knowledge in the engine to clarify this.</p>