- Lets say I create an initial array
let array = [1, "string", false]; //size : 3
- Now I add a new element at the index 40
array[40] = "fourty";
The memory for first 3 elements will be contiguous. The assumption is that this element at index 40 will be created at some random memory location. And the elements between index 3 to 38 will not be having any memory allocated.
So the question is how the JS manages to find the item at index 40 without even knowing where to look for ?