Skip to content

Arrays: Delete

Task: Remove 30 from this array

0123410204050REMOVED30out

What you are watching

Deleting is inserting in reverse. Removing 30 from index 2 leaves a hole, and an array is not allowed to have one, so every value after it moves one place left to close it. Two values move to remove one, and the slot at the end stops being part of the array. As with inserting, the cost is not the removal but everything that has to shift after it.