Are there limits to the number of properties in a JavaScript object?

In the current version of Chrome (Sept 2017), I’m limited to around 8.3 million keys. Try pasting this in your browser console:

let obj = {};
let keyCount = 0;
while(1) {
  obj[Math.random()] = Math.random();
  if(++keyCount % 10000 === 0) console.log(keyCount);
}

I get an identical limit in Node.js:

node --max-old-space-size=20000 -e "let obj = {}; let keyCount = 0; while(1) { obj[Math.random()] = Math.random(); if(++keyCount % 10000 === 0) console.log(keyCount); }"

Interestingly, if I use a Map, I can get about 16.8 million keys before it crashes (you can get past this limit with something like this).

Leave a Comment