Deleting array elements in JavaScript - delete vs splice -


Unlike using

, what is the difference between using the array element?

For example:

  myArray = ['A', 'B', 'C', 'D']; MyArray [1]; // or myArray.splice (1, 1);  

Why can I remove array elements like I can with objects if splice is also the method?

delete will remove the object property, but change the array again or Its length will not be updated. It seems like it is undefined:

  & gt; MyArray = ['A', 'B', 'C', 'D'] ["A", "B", "C", "D"] & gt; Removing MyArray [0] is true & gt; MyArray [Undefined, "B", "C", "D"]  

actually deletes the element:

  & gt; MyArray = ['A', 'B', 'C', 'D'] ["A", "B", "C", "D"] & gt; MyArray.splice (0, 2) ["A", "B"]> gt; MyArray ["c", "d"]  

Comments