.removeLast()

The .removeLast() method removes the last element in an array.

Syntax

arrayName.removeLast()

Example

var topBabyNames = ["Sophia", "Liam", "Riley", "Jackson", "Olivia", "Noah"]
topBabyNames.removeLast()
print(topBabyNames)

This will output:

["Sophia", "Liam", "Riley", "Jackson", "Olivia"]

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn Swift on Codecademy