In Javascript, if I have a very large array, myArray
And I add to it by calling myArray.push()
And I remove indexes using something like delete myArray[102]
Is there some benefit or reason to create a separate array like myArrayGaps
that holds which indexes in myArray
are not being used so that if there are unused ones, I add to the array by defining a specific index like myArray[102] = newValue;
instead of calling .push()
and accumulating unused indexes?
Or is that impractical and pointless because of some aspect of Javascript's memory handling?
The reason I am deleting instead of splicing is because I don't want to reorder the indexes of the array; I am using them to identify specific objects at specific indexes. I'm primarily asking if there is any reason to optimize my use of the gaps made when using delete
.