#40: delete arr[1]
Topic: arrays · Difficulty: ★★★
const arr = [1, 2, 3];
delete arr[1];
console.log(arr);
console.log(arr.length);Output
[ 1, <1 empty item>, 3 ] 3
Why
delete is a generic property-deletion operator — it removes the property at index 1 entirely, but it does NOT re-index the remaining elements and does NOT update .length, because length is only recalculated when elements are added, removed via splice/pop, or the length property itself is set. The array is left with a genuine hole (an empty slot, not undefined) between index 0 and index 2, while length still reports 3. This is why delete is almost never the right tool for removing array elements — splice(index, 1) removes the element AND shifts everything down, keeping the array dense.