modifies the last element of the array