0

I have an array which contains a few million elements; nearly half of the indexes will be empty. What is the most memory efficient way of filling these empty indexes?

My limited understanding is that both are stored as strings of their name; and each char in a string requires 2 bytes. So null being 4 chars is 8 bytes; while undefined is 8 chars or 16 bytes. If this is the case would it be better to store these index as an empty string?

  • There are some answers on this topic worth checking: https://stackoverflow.com/questions/6499352/does-null-occupy-memory-in-javascript https://stackoverflow.com/questions/50854916/javascript-memory-impact-of-null-vs-undefined – rpeshkov Jan 15 '20 at 23:14
  • Does this answer your question? [Javascript memory impact of null vs undefined](https://stackoverflow.com/questions/50854916/javascript-memory-impact-of-null-vs-undefined) – Evan Jan 15 '20 at 23:14

0 Answers0