I add a element to the array in a higher position than its length
I wonder if is there a way to access or delete this empty elements, I think it can waste memory
When doing this, you create a "sparse array". The items in between the non-null entries contain undefined
. As such, the memory footprint is negligible. You cannot delete them. If you don't like this behavior, just don't create sparse arrays.