.removeLast()

Christine_Yang's avatar
Published Oct 11, 2022
Contribute to Docs

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"]

All contributors

Contribute to Docs

Learn Swift on Codecademy