Here i have an array with elements whose indexes are separated by increments of 1.
let noGap = [];
noGap[0] = 0;
noGap[1] = 1;
Here I have a different array whose indexes are separated by indexes of much greater than 1.
let gap = [];
gap[0] = 0;
gap[1000] = 1;
What is the difference between how much memory each variable (noGap
vs gap
) uses? I can see from a Chrome console log that gap
has wider length, because it logs (1001) [0, undefined × 999, 1]
.
But if the gap
variable indeed uses more space, I'm interested to know if it's proportionate to the number of undefined
that exist in the array or if it's constant.
Pardon me if this is repeated question. This is the closest answer I found but I couldn't fully understand the answer.