How to delete an array element in JavaScript?

It is quite easy to delete an array element in JavaScript. When we delete an element we may want to preserve the array index and at the same time, we may want to delete the element along with the index.

We can delete the element by keeping the index in the following way:

Keeping the index

var myArray = ["a", "b", "c", "d"]
delete myArray[0];

// Output 
true

Delete element with index

var myArray = ["a", "b", "c", "d"]
myArray.splice(2, 1);
console.log(myArray)

// Output 
["a", "b", "d"]