In my array, the elements are indexed consecutively with a gap of 1 between each index.
let noGap = [];
noGap[0] = 0;
noGap[1] = 1;
On the other hand, I have a separate array where the indexes are much more spread out.
let gap = [];
gap[0] = 0;
gap[1000] = 1;
I'm curious about the difference in memory usage between the variables noGap
and gap
. When logged in Chrome console, gap
shows a wider length: (1001) [0, undefined × 999, 1]
.
If indeed gap
consumes more memory, I wonder if this increase is directly proportional to the number of undefined
values in the array or if it remains constant regardless.
Apologies if this question has been asked before. The closest answer I found was on this page, but I couldn't fully grasp the explanation provided.