Now that we can add elements to the array within the struct, we can also remove elements from the array. The challenge here is that you can only adjust the size of the array, meaning that you can only remove the last element. One simple way to remove an individual element is to use its position in the array to save the current last element, and then reduce the size of the array by one. This is shown in the following illustration and example.
Example
Notice how the code below checks the index is valid before attempting to remove the element. It is important to sanitise data, particularly in these functions that access array values. There are a range of security exploits that take advantage of code that does not perform these checks which can result in access to values you should not be able to access and potentially the ability to execute arbitrary code.