Removing elements from an array in JavaScript - differences between delete and splice

What are the distinctions between employing the delete operator versus the splice method when removing elements from an array?

Consider the following example:

let sampleArray = ['x', 'y', 'z', 'w'];

delete sampleArray[2];
// or 
sampleArray.splice(2, 1);

What purpose does the splice method serve if I can remove array items similar to how I handle object properties?

From my experience with JavaScript, delete really can mess with your array when you rely on its length or the index positions of elements, because the element is removed but the index still exists with undefined. I find splice offers a cleaner approach, especially when I need the array to stay compact with no ‘holes’. Plus, splice can also be used to insert elements, which adds more flexibility if you ever need to insert while removing. It’s quite handy for maintaining orderly data if the sequence matters.