2014-01-09

JavaScript: never use 「delete」 to remove element in array

Note: splice is the general way to add/remove elements. You should never use 「delete」 to remove elements in a array, because that creates a sparse array.

// example of how delete creates a sparse array
var aa = ["a", "b", "c"];
delete aa[1];
console.log(aa);                // [ 'a', , 'c' ]
console.log(aa.length);         // 3

see JavaScript Array Methods