As an example, when using the delete
operator on an index of an Array, the index is removed, such as any property of any object would be.
This is proven by:
var arr = ['one', 'two', 'three'];
delete arr[1];
if(1 in arr)
alert("It didn't work!");
If you were to run this block, you will find that the text "It didn't work!" will never be alerted to the user. This is because the property belonging as index 1
on the Array has been deleted.
Now, here is where things get weird...
Although an index is deleted from an Array, the Array length shall remain the same:
var arr = ['one', 'two', 'three'];
alert(arr.length); //will alert '3'
delete arr[2];
alert(arr.length); //will still alert '3'
When looking at the Array arr
in the debugger (in Chrome at least), you will see that the index 2
does not even exist, so why does the length still report as 3?